Skip to content

Commit 04e4354

Browse files
authored
Merge pull request #1168 from scottr-ad/master
Issue #1157 - AllOf references not resolved by parser, OneOf and AnyOf resolved correctly
2 parents 028a00f + 81d0a1d commit 04e4354

File tree

5 files changed

+130
-2
lines changed

5 files changed

+130
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ public Schema resolveSchema(Schema schema) {
291291

292292
// if we make it without a resolution loop, we can update the reference
293293
resolvedModels.put(ref, model);
294+
schemas.put(ref, model);
294295

295296
return model;
296297

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIResolverTest.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import static com.github.tomakehurst.wiremock.client.WireMock.get;
6767
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
6868
import static org.testng.Assert.assertEquals;
69+
import static org.testng.Assert.assertFalse;
6970
import static org.testng.Assert.assertNotNull;
7071
import static org.testng.Assert.assertNull;
7172
import static org.testng.Assert.assertTrue;
@@ -490,6 +491,29 @@ public void testIssue85(@Injectable final List<AuthorizationValue> auths) {
490491
assertTrue(prop instanceof Schema);
491492
}
492493

494+
@Test
495+
public void testIssue1157(@Injectable final List<AuthorizationValue> auths) {
496+
ParseOptions options = new ParseOptions();
497+
options.setResolve(true);
498+
options.setResolveFully(true);
499+
500+
OpenAPI openAPIAnyOf = new OpenAPIV3Parser().readLocation("/issue-1157/anyOf-example.yaml", auths, options).getOpenAPI();
501+
Schema petSchemaAnyOf = openAPIAnyOf.getComponents().getSchemas().get("Pet");
502+
assertTrue(petSchemaAnyOf instanceof ComposedSchema);
503+
assertTrue(((ComposedSchema) petSchemaAnyOf).getAnyOf() != null);
504+
505+
OpenAPI openAPIOneOf = new OpenAPIV3Parser().readLocation("/issue-1157/oneOf-example.yaml", auths, options).getOpenAPI();
506+
Schema petSchemaOneOf = openAPIOneOf.getComponents().getSchemas().get("Pet");
507+
assertTrue(petSchemaOneOf instanceof ComposedSchema);
508+
assertTrue(((ComposedSchema) petSchemaOneOf).getOneOf() != null);
509+
510+
OpenAPI openAPIAllOf = new OpenAPIV3Parser().readLocation("/issue-1157/allOf-example.yaml", auths, options).getOpenAPI();
511+
Schema petSchemaAllOf = openAPIAllOf.getComponents().getSchemas().get("Pet");
512+
assertFalse(petSchemaAllOf instanceof ComposedSchema);
513+
assertTrue(petSchemaAllOf.getProperties() != null);
514+
515+
}
516+
493517
@Test
494518
public void testIssue1161(@Injectable final List<AuthorizationValue> auths) {
495519
String path = "/issue-1161/swagger.yaml";
@@ -499,8 +523,6 @@ public void testIssue1161(@Injectable final List<AuthorizationValue> auths) {
499523
options.setResolveFully(true);
500524

501525
OpenAPI openAPI = new OpenAPIV3Parser().readLocation(path, auths, options).getOpenAPI();
502-
ResolverFully resolverUtil = new ResolverFully();
503-
resolverUtil.resolveFully(openAPI);
504526

505527
Schema petsSchema = openAPI.getComponents().getSchemas().get("Pets");
506528
Schema colouringsSchema = openAPI.getComponents().getSchemas().get("Colouring");
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 15.3.0
4+
title: test
5+
paths:
6+
/pets:
7+
get:
8+
description: "Test"
9+
responses:
10+
200:
11+
description: Parameters missing or invalid
12+
content:
13+
application/json:
14+
schema:
15+
$ref: '#/components/schemas/Pet'
16+
components:
17+
schemas:
18+
Dog:
19+
type: object
20+
properties:
21+
bark:
22+
type: boolean
23+
breed:
24+
type: string
25+
Cat:
26+
type: object
27+
properties:
28+
hunts:
29+
type: boolean
30+
age:
31+
type: integer
32+
Pet:
33+
allOf:
34+
- $ref: '#/components/schemas/Cat'
35+
- $ref: '#/components/schemas/Dog'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 15.3.0
4+
title: test
5+
paths:
6+
/pets:
7+
get:
8+
description: "Test"
9+
responses:
10+
200:
11+
description: Parameters missing or invalid
12+
content:
13+
application/json:
14+
schema:
15+
$ref: '#/components/schemas/Pet'
16+
components:
17+
schemas:
18+
Dog:
19+
type: object
20+
properties:
21+
bark:
22+
type: boolean
23+
breed:
24+
type: string
25+
Cat:
26+
type: object
27+
properties:
28+
hunts:
29+
type: boolean
30+
age:
31+
type: integer
32+
Pet:
33+
anyOf:
34+
- $ref: '#/components/schemas/Cat'
35+
- $ref: '#/components/schemas/Dog'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 15.3.0
4+
title: test
5+
paths:
6+
/pets:
7+
get:
8+
description: "Test"
9+
responses:
10+
200:
11+
description: Parameters missing or invalid
12+
content:
13+
application/json:
14+
schema:
15+
$ref: '#/components/schemas/Pet'
16+
components:
17+
schemas:
18+
Dog:
19+
type: object
20+
properties:
21+
bark:
22+
type: boolean
23+
breed:
24+
type: string
25+
Cat:
26+
type: object
27+
properties:
28+
hunts:
29+
type: boolean
30+
age:
31+
type: integer
32+
Pet:
33+
oneOf:
34+
- $ref: '#/components/schemas/Cat'
35+
- $ref: '#/components/schemas/Dog'

0 commit comments

Comments
 (0)