mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 14:40:53 +00:00
[core] consider schema in headers when computing unused schemas (#2138)
This commit is contained in:
parent
b6c2266a14
commit
598bf0cd09
@ -192,13 +192,23 @@ public class ModelUtils {
|
|||||||
if (operation.getResponses() != null) {
|
if (operation.getResponses() != null) {
|
||||||
for (ApiResponse r : operation.getResponses().values()) {
|
for (ApiResponse r : operation.getResponses().values()) {
|
||||||
ApiResponse apiResponse = getReferencedApiResponse(openAPI, r);
|
ApiResponse apiResponse = getReferencedApiResponse(openAPI, r);
|
||||||
if (apiResponse != null && apiResponse.getContent() != null) {
|
if (apiResponse != null) {
|
||||||
|
if (apiResponse.getContent() != null) {
|
||||||
for (Entry<String, MediaType> e : apiResponse.getContent().entrySet()) {
|
for (Entry<String, MediaType> e : apiResponse.getContent().entrySet()) {
|
||||||
if (e.getValue().getSchema() != null) {
|
if (e.getValue().getSchema() != null) {
|
||||||
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
visitSchema(openAPI, e.getValue().getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (apiResponse.getHeaders() != null) {
|
||||||
|
for (Entry<String, Header> e : apiResponse.getHeaders().entrySet()) {
|
||||||
|
Header header = getReferencedHeader(openAPI, e.getValue());
|
||||||
|
if (header.getSchema() != null) {
|
||||||
|
visitSchema(openAPI, header.getSchema(), e.getKey(), visitedSchemas, visitor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ public class ModelUtilsTest {
|
|||||||
public void testGetAllUsedSchemas() {
|
public void testGetAllUsedSchemas() {
|
||||||
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/unusedSchemas.yaml");
|
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/unusedSchemas.yaml");
|
||||||
List<String> allUsedSchemas = ModelUtils.getAllUsedSchemas(openAPI);
|
List<String> allUsedSchemas = ModelUtils.getAllUsedSchemas(openAPI);
|
||||||
Assert.assertEquals(allUsedSchemas.size(), 32);
|
Assert.assertEquals(allUsedSchemas.size(), 34);
|
||||||
|
|
||||||
Assert.assertTrue(allUsedSchemas.contains("SomeObjShared"), "contains 'SomeObjShared'");
|
Assert.assertTrue(allUsedSchemas.contains("SomeObjShared"), "contains 'SomeObjShared'");
|
||||||
Assert.assertTrue(allUsedSchemas.contains("SomeObj1"), "contains 'UnusedObj1'");
|
Assert.assertTrue(allUsedSchemas.contains("SomeObj1"), "contains 'UnusedObj1'");
|
||||||
@ -71,6 +71,8 @@ public class ModelUtilsTest {
|
|||||||
Assert.assertTrue(allUsedSchemas.contains("PingDataOutput21"), "contains 'PingDataOutput21'");
|
Assert.assertTrue(allUsedSchemas.contains("PingDataOutput21"), "contains 'PingDataOutput21'");
|
||||||
Assert.assertTrue(allUsedSchemas.contains("SInput22"), "contains 'SInput22'");
|
Assert.assertTrue(allUsedSchemas.contains("SInput22"), "contains 'SInput22'");
|
||||||
Assert.assertTrue(allUsedSchemas.contains("SOutput22"), "contains 'SInput22'");
|
Assert.assertTrue(allUsedSchemas.contains("SOutput22"), "contains 'SInput22'");
|
||||||
|
Assert.assertTrue(allUsedSchemas.contains("SomeHeader23"), "contains 'SomeHeader23'");
|
||||||
|
Assert.assertTrue(allUsedSchemas.contains("SomeHeader24"), "contains 'SomeHeader24'");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -280,6 +280,27 @@ paths:
|
|||||||
callbacks:
|
callbacks:
|
||||||
sharedCallback:
|
sharedCallback:
|
||||||
$ref: "#/components/callbacks/sharedCallback22"
|
$ref: "#/components/callbacks/sharedCallback22"
|
||||||
|
/some/p23:
|
||||||
|
post:
|
||||||
|
operationId: op23
|
||||||
|
responses:
|
||||||
|
'2XX':
|
||||||
|
description: OK
|
||||||
|
headers:
|
||||||
|
x-app-info:
|
||||||
|
description: basic app info
|
||||||
|
style: simple
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/SomeHeader23"
|
||||||
|
/some/p24:
|
||||||
|
post:
|
||||||
|
operationId: op24
|
||||||
|
responses:
|
||||||
|
'2XX':
|
||||||
|
description: OK
|
||||||
|
headers:
|
||||||
|
x-app-info:
|
||||||
|
$ref: "#/components/headers/sharedHeader24"
|
||||||
components:
|
components:
|
||||||
schemas:
|
schemas:
|
||||||
UnusedObj1:
|
UnusedObj1:
|
||||||
@ -538,6 +559,11 @@ components:
|
|||||||
type: String
|
type: String
|
||||||
response:
|
response:
|
||||||
type: String
|
type: String
|
||||||
|
SomeHeader23:
|
||||||
|
type: string
|
||||||
|
SomeHeader24:
|
||||||
|
type: integer
|
||||||
|
format: int64
|
||||||
SomeObjShared:
|
SomeObjShared:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -607,4 +633,9 @@ components:
|
|||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/components/schemas/SOutput22'
|
$ref: '#/components/schemas/SOutput22'
|
||||||
|
headers:
|
||||||
|
sharedHeader24:
|
||||||
|
description: basic header
|
||||||
|
style: simple
|
||||||
|
schema:
|
||||||
|
$ref: "#/components/schemas/SomeHeader24"
|
Loading…
x
Reference in New Issue
Block a user