Skip to content
Open
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 @@ -655,10 +655,14 @@ public Operation convert(io.swagger.models.Operation v2Operation) {

private Map<String, Object> convert(Map<String, Object> vendorExtensions) {
if (vendorExtensions != null && vendorExtensions.size() > 0) {
vendorExtensions.entrySet().removeIf(extension -> (
extension.getKey().equals("x-example")) ||
extension.getKey().equals("x-examples") ||
extension.getKey().equals("x-nullable"));
Map<String, Object> result = new LinkedHashMap<>();
for (Map.Entry<String, Object> entry : vendorExtensions.entrySet()) {
String key = entry.getKey();
if (!key.equals("x-example") && !key.equals("x-examples") && !key.equals("x-nullable")) {
result.put(key, entry.getValue());
}
}
return result;
}

return vendorExtensions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,32 @@ public void testIssue1552() throws Exception {
assertNotNull(schema.getProperties().get("foo"));
}

@Test(description = "Issue 2269: preserve x-nullable in shared responses for swagger 2.0 specs")
public void testSwagger2SharedResponseNullable() {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);

SwaggerParseResult result = new OpenAPIParser().readLocation("issue2269.yaml", null, options);

assertNotNull(result);
assertNotNull(result.getOpenAPI());
OpenAPI openAPI = result.getOpenAPI();

Schema endpoint1Field = (Schema) openAPI.getPaths().get("/endpoint1").getGet()
.getResponses().get("200").getContent().values().iterator().next()
.getSchema().getProperties().get("optional_field");
assertNotNull(endpoint1Field, "Endpoint 1 should have optional_field");
assertEquals(endpoint1Field.getNullable(), Boolean.TRUE, "Endpoint 1 optional_field should be nullable");

Schema endpoint2Field = (Schema) openAPI.getPaths().get("/endpoint2").getGet()
.getResponses().get("200").getContent().values().iterator().next()
.getSchema().getProperties().get("optional_field");
assertNotNull(endpoint2Field, "Endpoint 2 should have optional_field");
assertEquals(endpoint2Field.getNullable(), Boolean.TRUE, "Endpoint 2 optional_field should be nullable");

}

@org.testng.annotations.Test(description = "convert response schema")
public void testIssue1552AdditionalProps() throws Exception {
ParseOptions options = new ParseOptions();
Expand Down
38 changes: 38 additions & 0 deletions modules/swagger-parser/src/test/resources/issue2269.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
swagger: '2.0'
info:
version: 1.0.0
title: Swagger 2.0 Shared Response Test
description: Test case for verifying x-nullable is preserved when multiple endpoints share the same response definition

responses:
SharedResponse:
description: A shared response with nullable field
schema:
type: object
properties:
data:
type: string
description: Required field
optional_field:
type: integer
description: Optional nullable field
x-nullable: true
required:
- data

paths:
/endpoint1:
get:
operationId: endpoint1
summary: First endpoint using shared response
responses:
'200':
$ref: '#/responses/SharedResponse'

/endpoint2:
get:
operationId: endpoint2
summary: Second endpoint using shared response
responses:
'200':
$ref: '#/responses/SharedResponse'