forked from loafle/openapi-generator-original
[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) {
|
||||
for (ApiResponse r : operation.getResponses().values()) {
|
||||
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()) {
|
||||
if (e.getValue().getSchema() != null) {
|
||||
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() {
|
||||
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/unusedSchemas.yaml");
|
||||
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("SomeObj1"), "contains 'UnusedObj1'");
|
||||
@ -71,6 +71,8 @@ public class ModelUtilsTest {
|
||||
Assert.assertTrue(allUsedSchemas.contains("PingDataOutput21"), "contains 'PingDataOutput21'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SInput22"), "contains 'SInput22'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SOutput22"), "contains 'SInput22'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeHeader23"), "contains 'SomeHeader23'");
|
||||
Assert.assertTrue(allUsedSchemas.contains("SomeHeader24"), "contains 'SomeHeader24'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -280,6 +280,27 @@ paths:
|
||||
callbacks:
|
||||
sharedCallback:
|
||||
$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:
|
||||
schemas:
|
||||
UnusedObj1:
|
||||
@ -538,6 +559,11 @@ components:
|
||||
type: String
|
||||
response:
|
||||
type: String
|
||||
SomeHeader23:
|
||||
type: string
|
||||
SomeHeader24:
|
||||
type: integer
|
||||
format: int64
|
||||
SomeObjShared:
|
||||
type: object
|
||||
properties:
|
||||
@ -607,4 +633,9 @@ components:
|
||||
application/json:
|
||||
schema:
|
||||
$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