Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,20 @@ private static void visitPathItem(PathItem pathItem, OpenAPI openAPI, OpenAPISch
if (operation.getResponses() != null) {
for (ApiResponse r : operation.getResponses().values()) {
ApiResponse apiResponse = getReferencedApiResponse(openAPI, r);
if (apiResponse != null && 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 != 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);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'");
Expand Down Expand Up @@ -71,6 +71,8 @@ public void testGetAllUsedSchemas() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -538,6 +559,11 @@ components:
type: String
response:
type: String
SomeHeader23:
type: string
SomeHeader24:
type: integer
format: int64
SomeObjShared:
type: object
properties:
Expand Down Expand Up @@ -607,4 +633,9 @@ components:
application/json:
schema:
$ref: '#/components/schemas/SOutput22'

headers:
sharedHeader24:
description: basic header
style: simple
schema:
$ref: "#/components/schemas/SomeHeader24"