From 9cb2e39819a69dbb06e8beb5c7b42f2d24d20491 Mon Sep 17 00:00:00 2001 From: Chinmesh Manjrekar Date: Fri, 9 Jan 2026 11:38:00 +0000 Subject: [PATCH 1/2] Issue #2157 Resolve additionalProperties inside ComposedSchema correctly --- .../swagger/v3/parser/util/ResolverFully.java | 3 ++ .../io/swagger/parser/OpenAPIParserTest.java | 52 +++++++++++++++++++ .../additionalProperties_allOf_v1.yaml | 25 +++++++++ .../additionalProperties_allOf_v2.yaml | 26 ++++++++++ .../additionalProperties_allOf_v3.yaml | 27 ++++++++++ .../additionalProperties_allOf_v4.yaml | 27 ++++++++++ 6 files changed, 160 insertions(+) create mode 100644 modules/swagger-parser/src/test/resources/additionalProperties_allOf_v1.yaml create mode 100644 modules/swagger-parser/src/test/resources/additionalProperties_allOf_v2.yaml create mode 100644 modules/swagger-parser/src/test/resources/additionalProperties_allOf_v3.yaml create mode 100644 modules/swagger-parser/src/test/resources/additionalProperties_allOf_v4.yaml diff --git a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java index 3f3e19ec3b..5d9c400e28 100644 --- a/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java +++ b/modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java @@ -683,6 +683,9 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ if (resolved.getMinContains() != null) { targetSchema.setMinContains(resolved.getMinContains()); } + if (resolved.getAdditionalProperties() != null) { + targetSchema.setAdditionalProperties(resolved.getAdditionalProperties()); + } } if (requiredProperties.size() > 0) { diff --git a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java index ada569d28d..1e0f3dcbcb 100644 --- a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java +++ b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java @@ -25,6 +25,7 @@ import java.util.List; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertTrue; import static org.testng.AssertJUnit.assertNull; @@ -772,5 +773,56 @@ public void testIssue1552AdditionalProps() throws Exception { "openapi31: false\n"); } + + @Test + public void testAdditionalPropertiesWithAllOfV1() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "additionalProperties_allOf_v1.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAdditionalProperties()); + assertTrue((Boolean) schema.getAdditionalProperties()); + } + @Test + public void testAdditionalPropertiesWithAllOfV2() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "additionalProperties_allOf_v2.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAdditionalProperties()); + assertTrue((Boolean) schema.getAdditionalProperties()); + } + + @Test + public void testAdditionalPropertiesWithAllOfV3() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "additionalProperties_allOf_v3.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAdditionalProperties()); + assertTrue((Boolean) schema.getAdditionalProperties()); + } + + @Test + public void testAdditionalPropertiesWithAllOfV4() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "additionalProperties_allOf_v4.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAdditionalProperties()); + assertFalse((Boolean) schema.getAdditionalProperties()); + } } diff --git a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v1.yaml b/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v1.yaml new file mode 100644 index 0000000000..216e1f6f8c --- /dev/null +++ b/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v1.yaml @@ -0,0 +1,25 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + ObjectWithAdditionalProperties: + type: object + additionalProperties: true + properties: + name: + type: string + TestSchema: + allOf: + - $ref: '#/components/schemas/ObjectWithAdditionalProperties' diff --git a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v2.yaml b/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v2.yaml new file mode 100644 index 0000000000..0bb630f75d --- /dev/null +++ b/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v2.yaml @@ -0,0 +1,26 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + ObjectWithAdditionalProperties: + type: object + additionalProperties: true + TestSchema: + allOf: + - $ref: '#/components/schemas/ObjectWithAdditionalProperties' + - type: object + properties: + name: + type: string diff --git a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v3.yaml b/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v3.yaml new file mode 100644 index 0000000000..e51efb2e81 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v3.yaml @@ -0,0 +1,27 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + ObjectWithAdditionalProperties: + type: object + additionalProperties: true + TestSchema: + allOf: + - type: object + properties: + name: + type: string + additionalProperties: false + - $ref: '#/components/schemas/ObjectWithAdditionalProperties' diff --git a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v4.yaml b/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v4.yaml new file mode 100644 index 0000000000..b52821be84 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v4.yaml @@ -0,0 +1,27 @@ +openapi: 3.0.1 +info: + title: Test API + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + ObjectWithAdditionalProperties: + type: object + additionalProperties: true + TestSchema: + allOf: + - $ref: '#/components/schemas/ObjectWithAdditionalProperties' + - type: object + properties: + name: + type: string + additionalProperties: false From 9233c2d785333fd89563e9115632712e481a08a4 Mon Sep 17 00:00:00 2001 From: Ewa Ostrowska Date: Tue, 14 Apr 2026 14:34:14 +0200 Subject: [PATCH 2/2] add tests --- .../io/swagger/parser/OpenAPIParserTest.java | 222 ++++++++++++++++-- .../allOf-conflict-last-wins-inline.yaml} | 4 +- .../allOf-conflict-last-wins-ref.yaml} | 4 +- .../allOf-conflict-schema-objects.yaml | 36 +++ ...Of-no-aggregation-preserves-structure.yaml | 29 +++ .../allOf-preserves-schema-object.yaml | 31 +++ ...lOf-preserves-schema-with-constraints.yaml | 32 +++ .../allOf-ref-and-inline-merge.yaml} | 0 .../allOf-single-ref-boolean.yaml} | 0 .../anyOf-multiple-branches-independent.yaml | 26 ++ .../issue-2157/anyOf-preserves-boolean.yaml | 25 ++ .../anyOf-preserves-schema-object.yaml | 29 +++ .../oneOf-multiple-branches-independent.yaml | 26 ++ .../issue-2157/oneOf-preserves-boolean.yaml | 25 ++ .../oneOf-preserves-schema-object.yaml | 29 +++ 15 files changed, 495 insertions(+), 23 deletions(-) rename modules/swagger-parser/src/test/resources/{additionalProperties_allOf_v3.yaml => issue-2157/allOf-conflict-last-wins-inline.yaml} (89%) rename modules/swagger-parser/src/test/resources/{additionalProperties_allOf_v4.yaml => issue-2157/allOf-conflict-last-wins-ref.yaml} (89%) create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-schema-objects.yaml create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/allOf-no-aggregation-preserves-structure.yaml create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/allOf-preserves-schema-object.yaml create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/allOf-preserves-schema-with-constraints.yaml rename modules/swagger-parser/src/test/resources/{additionalProperties_allOf_v2.yaml => issue-2157/allOf-ref-and-inline-merge.yaml} (100%) rename modules/swagger-parser/src/test/resources/{additionalProperties_allOf_v1.yaml => issue-2157/allOf-single-ref-boolean.yaml} (100%) create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/anyOf-multiple-branches-independent.yaml create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/anyOf-preserves-boolean.yaml create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/anyOf-preserves-schema-object.yaml create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/oneOf-multiple-branches-independent.yaml create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/oneOf-preserves-boolean.yaml create mode 100644 modules/swagger-parser/src/test/resources/issue-2157/oneOf-preserves-schema-object.yaml diff --git a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java index 1e0f3dcbcb..936b17f1d0 100644 --- a/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java +++ b/modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java @@ -40,7 +40,7 @@ public void testNPE_1685() { SwaggerParseResult swaggerParseResult = openAPIParser.readLocation("issue1685.json", null, options); assertNull(swaggerParseResult.getOpenAPI()); assertNotNull(swaggerParseResult.getMessages()); - assertTrue(swaggerParseResult.getMessages().size() == 2); + assertTrue(swaggerParseResult.getMessages().size() == 2); assertEquals(swaggerParseResult.getMessages().get(0), "attribute notswagger is unexpected"); assertEquals(swaggerParseResult.getMessages().get(1), "attribute swagger is missing"); } @@ -775,36 +775,24 @@ public void testIssue1552AdditionalProps() throws Exception { @Test - public void testAdditionalPropertiesWithAllOfV1() { + public void testIssue2157_AllOf_SingleRefPreservesBoolean() { ParseOptions options = new ParseOptions(); options.setResolveFully(true); SwaggerParseResult result = new OpenAPIParser().readLocation( - "additionalProperties_allOf_v1.yaml", null, options); + "issue-2157/allOf-single-ref-boolean.yaml", null, options); assertNotNull(result.getOpenAPI()); Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); assertNotNull(schema); assertNotNull(schema.getAdditionalProperties()); assertTrue((Boolean) schema.getAdditionalProperties()); } - @Test - public void testAdditionalPropertiesWithAllOfV2() { - ParseOptions options = new ParseOptions(); - options.setResolveFully(true); - SwaggerParseResult result = new OpenAPIParser().readLocation( - "additionalProperties_allOf_v2.yaml", null, options); - assertNotNull(result.getOpenAPI()); - Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); - assertNotNull(schema); - assertNotNull(schema.getAdditionalProperties()); - assertTrue((Boolean) schema.getAdditionalProperties()); - } @Test - public void testAdditionalPropertiesWithAllOfV3() { + public void testIssue2157_AllOf_RefAndInlineMerge() { ParseOptions options = new ParseOptions(); options.setResolveFully(true); SwaggerParseResult result = new OpenAPIParser().readLocation( - "additionalProperties_allOf_v3.yaml", null, options); + "issue-2157/allOf-ref-and-inline-merge.yaml", null, options); assertNotNull(result.getOpenAPI()); Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); assertNotNull(schema); @@ -813,16 +801,212 @@ public void testAdditionalPropertiesWithAllOfV3() { } @Test - public void testAdditionalPropertiesWithAllOfV4() { + public void testIssue2157_AllOf_PreservesSchemaObject() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/allOf-preserves-schema-object.yaml", null, options); + assertNotNull(result.getOpenAPI()); + RequestBody requestBody = result.getOpenAPI().getPaths().get("/pet").getPut().getRequestBody(); + assertNotNull(requestBody); + Schema schema = requestBody.getContent().get("application/json").getSchema(); + assertNotNull(schema); + assertNotNull(schema.getAdditionalProperties()); + assertTrue(schema.getAdditionalProperties() instanceof Schema); + Schema additionalPropsSchema = (Schema) schema.getAdditionalProperties(); + assertEquals(additionalPropsSchema.getType(), "string"); + assertNotNull(schema.getProperties()); + assertTrue(schema.getProperties().containsKey("id")); + assertTrue(schema.getProperties().containsKey("name")); + } + + @Test + public void testIssue2157_AllOf_PreservesSchemaWithConstraints() { ParseOptions options = new ParseOptions(); options.setResolveFully(true); SwaggerParseResult result = new OpenAPIParser().readLocation( - "additionalProperties_allOf_v4.yaml", null, options); + "issue-2157/allOf-preserves-schema-with-constraints.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAdditionalProperties()); + assertTrue(schema.getAdditionalProperties() instanceof Schema); + Schema additionalPropsSchema = (Schema) schema.getAdditionalProperties(); + assertEquals(additionalPropsSchema.getType(), "string"); + assertEquals(additionalPropsSchema.getMinLength(), Integer.valueOf(1)); + assertEquals(additionalPropsSchema.getMaxLength(), Integer.valueOf(100)); + assertNotNull(schema.getProperties()); + assertTrue(schema.getProperties().containsKey("id")); + assertTrue(schema.getProperties().containsKey("name")); + } + + @Test + public void testIssue2157_AllOf_ConflictLastWinsInline() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/allOf-conflict-last-wins-inline.yaml", null, options); assertNotNull(result.getOpenAPI()); Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); assertNotNull(schema); assertNotNull(schema.getAdditionalProperties()); assertFalse((Boolean) schema.getAdditionalProperties()); } + + @Test + public void testIssue2157_AllOf_ConflictLastWinsRef() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/allOf-conflict-last-wins-ref.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAdditionalProperties()); + assertTrue((Boolean) schema.getAdditionalProperties()); + } + + @Test + public void testIssue2157_AllOf_NoAggregationPreservesStructure() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + options.setResolveCombinators(false); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/allOf-no-aggregation-preserves-structure.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAllOf()); + assertEquals(schema.getAllOf().size(), 2); + Schema firstBranch = (Schema) schema.getAllOf().get(0); + assertNotNull(firstBranch.getAdditionalProperties()); + assertTrue((Boolean) firstBranch.getAdditionalProperties()); + } + + @Test + public void testIssue2157_AllOf_ConflictSchemaObjects() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/allOf-conflict-schema-objects.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAdditionalProperties()); + assertTrue(schema.getAdditionalProperties() instanceof Schema); + Schema additionalPropsSchema = (Schema) schema.getAdditionalProperties(); + assertEquals(additionalPropsSchema.getType(), "number"); + assertNotNull(schema.getProperties()); + assertTrue(schema.getProperties().containsKey("name")); + assertTrue(schema.getProperties().containsKey("id")); + } + + @Test + public void testIssue2157_OneOf_PreservesBoolean() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/oneOf-preserves-boolean.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getOneOf()); + assertEquals(schema.getOneOf().size(), 1); + Schema oneOfBranch = (Schema) schema.getOneOf().get(0); + assertNotNull(oneOfBranch.getAdditionalProperties()); + assertTrue((Boolean) oneOfBranch.getAdditionalProperties()); + } + + @Test + public void testIssue2157_OneOf_PreservesSchemaObject() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/oneOf-preserves-schema-object.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getOneOf()); + assertEquals(schema.getOneOf().size(), 1); + Schema oneOfBranch = (Schema) schema.getOneOf().get(0); + assertNotNull(oneOfBranch.getAdditionalProperties()); + assertTrue(oneOfBranch.getAdditionalProperties() instanceof Schema); + Schema additionalPropsSchema = (Schema) oneOfBranch.getAdditionalProperties(); + assertEquals(additionalPropsSchema.getType(), "string"); + assertEquals(additionalPropsSchema.getMinLength(), Integer.valueOf(1)); + } + + @Test + public void testIssue2157_OneOf_MultipleBranchesIndependent() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/oneOf-multiple-branches-independent.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getOneOf()); + assertEquals(schema.getOneOf().size(), 2); + Schema firstBranch = (Schema) schema.getOneOf().get(0); + Schema secondBranch = (Schema) schema.getOneOf().get(1); + assertNotNull(firstBranch.getAdditionalProperties()); + assertTrue((Boolean) firstBranch.getAdditionalProperties()); + assertNotNull(secondBranch.getAdditionalProperties()); + assertFalse((Boolean) secondBranch.getAdditionalProperties()); + } + + @Test + public void testIssue2157_AnyOf_PreservesBoolean() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/anyOf-preserves-boolean.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAnyOf()); + assertEquals(schema.getAnyOf().size(), 1); + Schema anyOfBranch = (Schema) schema.getAnyOf().get(0); + assertNotNull(anyOfBranch.getAdditionalProperties()); + assertTrue((Boolean) anyOfBranch.getAdditionalProperties()); + } + + @Test + public void testIssue2157_AnyOf_PreservesSchemaObject() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/anyOf-preserves-schema-object.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAnyOf()); + assertEquals(schema.getAnyOf().size(), 1); + Schema anyOfBranch = (Schema) schema.getAnyOf().get(0); + assertNotNull(anyOfBranch.getAdditionalProperties()); + assertTrue(anyOfBranch.getAdditionalProperties() instanceof Schema); + Schema additionalPropsSchema = (Schema) anyOfBranch.getAdditionalProperties(); + assertEquals(additionalPropsSchema.getType(), "string"); + assertEquals(additionalPropsSchema.getMinLength(), Integer.valueOf(1)); + } + + @Test + public void testIssue2157_AnyOf_MultipleBranchesIndependent() { + ParseOptions options = new ParseOptions(); + options.setResolveFully(true); + SwaggerParseResult result = new OpenAPIParser().readLocation( + "issue-2157/anyOf-multiple-branches-independent.yaml", null, options); + assertNotNull(result.getOpenAPI()); + Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema"); + assertNotNull(schema); + assertNotNull(schema.getAnyOf()); + assertEquals(schema.getAnyOf().size(), 2); + Schema firstBranch = (Schema) schema.getAnyOf().get(0); + Schema secondBranch = (Schema) schema.getAnyOf().get(1); + assertNotNull(firstBranch.getAdditionalProperties()); + assertTrue((Boolean) firstBranch.getAdditionalProperties()); + assertNotNull(secondBranch.getAdditionalProperties()); + assertFalse((Boolean) secondBranch.getAdditionalProperties()); + } } diff --git a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v3.yaml b/modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-last-wins-inline.yaml similarity index 89% rename from modules/swagger-parser/src/test/resources/additionalProperties_allOf_v3.yaml rename to modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-last-wins-inline.yaml index e51efb2e81..69ba1b6377 100644 --- a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v3.yaml +++ b/modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-last-wins-inline.yaml @@ -1,6 +1,6 @@ openapi: 3.0.1 info: - title: Test API + title: Test API - Conflict with $ref first (last non-null wins) version: 1.0.0 paths: /test: @@ -19,9 +19,9 @@ components: additionalProperties: true TestSchema: allOf: + - $ref: '#/components/schemas/ObjectWithAdditionalProperties' - type: object properties: name: type: string additionalProperties: false - - $ref: '#/components/schemas/ObjectWithAdditionalProperties' diff --git a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v4.yaml b/modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-last-wins-ref.yaml similarity index 89% rename from modules/swagger-parser/src/test/resources/additionalProperties_allOf_v4.yaml rename to modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-last-wins-ref.yaml index b52821be84..82d87ef608 100644 --- a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v4.yaml +++ b/modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-last-wins-ref.yaml @@ -1,6 +1,6 @@ openapi: 3.0.1 info: - title: Test API + title: Test API - Conflict with inline first (last non-null wins) version: 1.0.0 paths: /test: @@ -19,9 +19,9 @@ components: additionalProperties: true TestSchema: allOf: - - $ref: '#/components/schemas/ObjectWithAdditionalProperties' - type: object properties: name: type: string additionalProperties: false + - $ref: '#/components/schemas/ObjectWithAdditionalProperties' diff --git a/modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-schema-objects.yaml b/modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-schema-objects.yaml new file mode 100644 index 0000000000..d0025be07f --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/allOf-conflict-schema-objects.yaml @@ -0,0 +1,36 @@ +openapi: 3.0.1 +info: + title: Test API - Multiple schema-object additionalProperties conflict + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + SchemaWithStringAdditional: + type: object + properties: + name: + type: string + additionalProperties: + type: string + minLength: 1 + SchemaWithNumberAdditional: + type: object + properties: + id: + type: integer + additionalProperties: + type: number + minimum: 0 + TestSchema: + allOf: + - $ref: '#/components/schemas/SchemaWithStringAdditional' + - $ref: '#/components/schemas/SchemaWithNumberAdditional' diff --git a/modules/swagger-parser/src/test/resources/issue-2157/allOf-no-aggregation-preserves-structure.yaml b/modules/swagger-parser/src/test/resources/issue-2157/allOf-no-aggregation-preserves-structure.yaml new file mode 100644 index 0000000000..510edc67d8 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/allOf-no-aggregation-preserves-structure.yaml @@ -0,0 +1,29 @@ +openapi: 3.0.1 +info: + title: Test API - resolveCombinators=false preserves structure + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + BaseSchema: + type: object + properties: + id: + type: integer + additionalProperties: true + TestSchema: + allOf: + - $ref: '#/components/schemas/BaseSchema' + - type: object + properties: + name: + type: string diff --git a/modules/swagger-parser/src/test/resources/issue-2157/allOf-preserves-schema-object.yaml b/modules/swagger-parser/src/test/resources/issue-2157/allOf-preserves-schema-object.yaml new file mode 100644 index 0000000000..6f5ce95b6d --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/allOf-preserves-schema-object.yaml @@ -0,0 +1,31 @@ +openapi: 3.0.1 +info: + title: Test API for Issue 2157 + version: 1.0.0 +paths: + /pet: + put: + requestBody: + description: Update an existent pet in the store + content: + application/json: + schema: + allOf: + - $ref: '#/components/schemas/Pet' + responses: + '200': + description: OK +components: + schemas: + Pet: + type: object + properties: + id: + type: integer + format: int64 + example: 10 + name: + type: string + example: doggie + additionalProperties: + type: string diff --git a/modules/swagger-parser/src/test/resources/issue-2157/allOf-preserves-schema-with-constraints.yaml b/modules/swagger-parser/src/test/resources/issue-2157/allOf-preserves-schema-with-constraints.yaml new file mode 100644 index 0000000000..c1680fd13a --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/allOf-preserves-schema-with-constraints.yaml @@ -0,0 +1,32 @@ +openapi: 3.0.1 +info: + title: Test API - Schema Object additionalProperties + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + BaseSchema: + type: object + properties: + id: + type: integer + additionalProperties: + type: string + minLength: 1 + maxLength: 100 + TestSchema: + allOf: + - $ref: '#/components/schemas/BaseSchema' + - type: object + properties: + name: + type: string diff --git a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v2.yaml b/modules/swagger-parser/src/test/resources/issue-2157/allOf-ref-and-inline-merge.yaml similarity index 100% rename from modules/swagger-parser/src/test/resources/additionalProperties_allOf_v2.yaml rename to modules/swagger-parser/src/test/resources/issue-2157/allOf-ref-and-inline-merge.yaml diff --git a/modules/swagger-parser/src/test/resources/additionalProperties_allOf_v1.yaml b/modules/swagger-parser/src/test/resources/issue-2157/allOf-single-ref-boolean.yaml similarity index 100% rename from modules/swagger-parser/src/test/resources/additionalProperties_allOf_v1.yaml rename to modules/swagger-parser/src/test/resources/issue-2157/allOf-single-ref-boolean.yaml diff --git a/modules/swagger-parser/src/test/resources/issue-2157/anyOf-multiple-branches-independent.yaml b/modules/swagger-parser/src/test/resources/issue-2157/anyOf-multiple-branches-independent.yaml new file mode 100644 index 0000000000..799a381531 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/anyOf-multiple-branches-independent.yaml @@ -0,0 +1,26 @@ +openapi: 3.0.1 +info: + title: Test API - anyOf conflict last wins + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + ObjectWithAdditionalPropertiesTrue: + type: object + additionalProperties: true + ObjectWithAdditionalPropertiesFalse: + type: object + additionalProperties: false + TestSchema: + anyOf: + - $ref: '#/components/schemas/ObjectWithAdditionalPropertiesTrue' + - $ref: '#/components/schemas/ObjectWithAdditionalPropertiesFalse' diff --git a/modules/swagger-parser/src/test/resources/issue-2157/anyOf-preserves-boolean.yaml b/modules/swagger-parser/src/test/resources/issue-2157/anyOf-preserves-boolean.yaml new file mode 100644 index 0000000000..b2f558c527 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/anyOf-preserves-boolean.yaml @@ -0,0 +1,25 @@ +openapi: 3.0.1 +info: + title: Test API - additionalProperties with anyOf + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + ObjectWithAdditionalProperties: + type: object + additionalProperties: true + properties: + name: + type: string + TestSchema: + anyOf: + - $ref: '#/components/schemas/ObjectWithAdditionalProperties' diff --git a/modules/swagger-parser/src/test/resources/issue-2157/anyOf-preserves-schema-object.yaml b/modules/swagger-parser/src/test/resources/issue-2157/anyOf-preserves-schema-object.yaml new file mode 100644 index 0000000000..52e0ca5948 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/anyOf-preserves-schema-object.yaml @@ -0,0 +1,29 @@ +openapi: 3.0.1 +info: + title: Test API - additionalProperties schema-object with anyOf + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + Pet: + type: object + properties: + id: + type: integer + name: + type: string + additionalProperties: + type: string + minLength: 1 + TestSchema: + anyOf: + - $ref: '#/components/schemas/Pet' diff --git a/modules/swagger-parser/src/test/resources/issue-2157/oneOf-multiple-branches-independent.yaml b/modules/swagger-parser/src/test/resources/issue-2157/oneOf-multiple-branches-independent.yaml new file mode 100644 index 0000000000..61245c59dc --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/oneOf-multiple-branches-independent.yaml @@ -0,0 +1,26 @@ +openapi: 3.0.1 +info: + title: Test API - oneOf conflict last wins + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + ObjectWithAdditionalPropertiesTrue: + type: object + additionalProperties: true + ObjectWithAdditionalPropertiesFalse: + type: object + additionalProperties: false + TestSchema: + oneOf: + - $ref: '#/components/schemas/ObjectWithAdditionalPropertiesTrue' + - $ref: '#/components/schemas/ObjectWithAdditionalPropertiesFalse' diff --git a/modules/swagger-parser/src/test/resources/issue-2157/oneOf-preserves-boolean.yaml b/modules/swagger-parser/src/test/resources/issue-2157/oneOf-preserves-boolean.yaml new file mode 100644 index 0000000000..ab04c66038 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/oneOf-preserves-boolean.yaml @@ -0,0 +1,25 @@ +openapi: 3.0.1 +info: + title: Test API - additionalProperties with oneOf + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + ObjectWithAdditionalProperties: + type: object + additionalProperties: true + properties: + name: + type: string + TestSchema: + oneOf: + - $ref: '#/components/schemas/ObjectWithAdditionalProperties' diff --git a/modules/swagger-parser/src/test/resources/issue-2157/oneOf-preserves-schema-object.yaml b/modules/swagger-parser/src/test/resources/issue-2157/oneOf-preserves-schema-object.yaml new file mode 100644 index 0000000000..80d6d579a8 --- /dev/null +++ b/modules/swagger-parser/src/test/resources/issue-2157/oneOf-preserves-schema-object.yaml @@ -0,0 +1,29 @@ +openapi: 3.0.1 +info: + title: Test API - additionalProperties schema-object with oneOf + version: 1.0.0 +paths: + /test: + get: + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/TestSchema' +components: + schemas: + Pet: + type: object + properties: + id: + type: integer + name: + type: string + additionalProperties: + type: string + minLength: 1 + TestSchema: + oneOf: + - $ref: '#/components/schemas/Pet'