Skip to content

Commit b505ae5

Browse files
chinmeshatgoogleewaostrowska
authored andcommitted
Issue #2157 Resolve additionalProperties inside ComposedSchema correctly
1 parent afc1742 commit b505ae5

6 files changed

Lines changed: 160 additions & 0 deletions

File tree

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/util/ResolverFully.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,9 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ
687687
if (resolved.getMinContains() != null) {
688688
targetSchema.setMinContains(resolved.getMinContains());
689689
}
690+
if (resolved.getAdditionalProperties() != null) {
691+
targetSchema.setAdditionalProperties(resolved.getAdditionalProperties());
692+
}
690693
}
691694

692695
if (requiredProperties.size() > 0) {

modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.List;
2626

2727
import static org.testng.Assert.assertEquals;
28+
import static org.testng.Assert.assertFalse;
2829
import static org.testng.Assert.assertNotNull;
2930
import static org.testng.Assert.assertTrue;
3031
import static org.testng.AssertJUnit.assertNull;
@@ -772,5 +773,56 @@ public void testIssue1552AdditionalProps() throws Exception {
772773
"openapi31: false\n");
773774
}
774775

776+
777+
@Test
778+
public void testAdditionalPropertiesWithAllOfV1() {
779+
ParseOptions options = new ParseOptions();
780+
options.setResolveFully(true);
781+
SwaggerParseResult result = new OpenAPIParser().readLocation(
782+
"additionalProperties_allOf_v1.yaml", null, options);
783+
assertNotNull(result.getOpenAPI());
784+
Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema");
785+
assertNotNull(schema);
786+
assertNotNull(schema.getAdditionalProperties());
787+
assertTrue((Boolean) schema.getAdditionalProperties());
788+
}
789+
@Test
790+
public void testAdditionalPropertiesWithAllOfV2() {
791+
ParseOptions options = new ParseOptions();
792+
options.setResolveFully(true);
793+
SwaggerParseResult result = new OpenAPIParser().readLocation(
794+
"additionalProperties_allOf_v2.yaml", null, options);
795+
assertNotNull(result.getOpenAPI());
796+
Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema");
797+
assertNotNull(schema);
798+
assertNotNull(schema.getAdditionalProperties());
799+
assertTrue((Boolean) schema.getAdditionalProperties());
800+
}
801+
802+
@Test
803+
public void testAdditionalPropertiesWithAllOfV3() {
804+
ParseOptions options = new ParseOptions();
805+
options.setResolveFully(true);
806+
SwaggerParseResult result = new OpenAPIParser().readLocation(
807+
"additionalProperties_allOf_v3.yaml", null, options);
808+
assertNotNull(result.getOpenAPI());
809+
Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema");
810+
assertNotNull(schema);
811+
assertNotNull(schema.getAdditionalProperties());
812+
assertTrue((Boolean) schema.getAdditionalProperties());
813+
}
814+
815+
@Test
816+
public void testAdditionalPropertiesWithAllOfV4() {
817+
ParseOptions options = new ParseOptions();
818+
options.setResolveFully(true);
819+
SwaggerParseResult result = new OpenAPIParser().readLocation(
820+
"additionalProperties_allOf_v4.yaml", null, options);
821+
assertNotNull(result.getOpenAPI());
822+
Schema schema = result.getOpenAPI().getComponents().getSchemas().get("TestSchema");
823+
assertNotNull(schema);
824+
assertNotNull(schema.getAdditionalProperties());
825+
assertFalse((Boolean) schema.getAdditionalProperties());
826+
}
775827
}
776828

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/TestSchema'
15+
components:
16+
schemas:
17+
ObjectWithAdditionalProperties:
18+
type: object
19+
additionalProperties: true
20+
properties:
21+
name:
22+
type: string
23+
TestSchema:
24+
allOf:
25+
- $ref: '#/components/schemas/ObjectWithAdditionalProperties'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/TestSchema'
15+
components:
16+
schemas:
17+
ObjectWithAdditionalProperties:
18+
type: object
19+
additionalProperties: true
20+
TestSchema:
21+
allOf:
22+
- $ref: '#/components/schemas/ObjectWithAdditionalProperties'
23+
- type: object
24+
properties:
25+
name:
26+
type: string
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/TestSchema'
15+
components:
16+
schemas:
17+
ObjectWithAdditionalProperties:
18+
type: object
19+
additionalProperties: true
20+
TestSchema:
21+
allOf:
22+
- type: object
23+
properties:
24+
name:
25+
type: string
26+
additionalProperties: false
27+
- $ref: '#/components/schemas/ObjectWithAdditionalProperties'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
openapi: 3.0.1
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
paths:
6+
/test:
7+
get:
8+
responses:
9+
'200':
10+
description: OK
11+
content:
12+
application/json:
13+
schema:
14+
$ref: '#/components/schemas/TestSchema'
15+
components:
16+
schemas:
17+
ObjectWithAdditionalProperties:
18+
type: object
19+
additionalProperties: true
20+
TestSchema:
21+
allOf:
22+
- $ref: '#/components/schemas/ObjectWithAdditionalProperties'
23+
- type: object
24+
properties:
25+
name:
26+
type: string
27+
additionalProperties: false

0 commit comments

Comments
 (0)