Skip to content

Commit

Permalink
Merge pull request #1168 from scottr-ad/master
Browse files Browse the repository at this point in the history
Issue #1157 - AllOf references not resolved by parser, OneOf and AnyOf resolved correctly
  • Loading branch information
gracekarina authored Aug 14, 2019
2 parents 028a00f + 81d0a1d commit 04e4354
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public Schema resolveSchema(Schema schema) {

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

return model;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
Expand Down Expand Up @@ -490,6 +491,29 @@ public void testIssue85(@Injectable final List<AuthorizationValue> auths) {
assertTrue(prop instanceof Schema);
}

@Test
public void testIssue1157(@Injectable final List<AuthorizationValue> auths) {
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);

OpenAPI openAPIAnyOf = new OpenAPIV3Parser().readLocation("/issue-1157/anyOf-example.yaml", auths, options).getOpenAPI();
Schema petSchemaAnyOf = openAPIAnyOf.getComponents().getSchemas().get("Pet");
assertTrue(petSchemaAnyOf instanceof ComposedSchema);
assertTrue(((ComposedSchema) petSchemaAnyOf).getAnyOf() != null);

OpenAPI openAPIOneOf = new OpenAPIV3Parser().readLocation("/issue-1157/oneOf-example.yaml", auths, options).getOpenAPI();
Schema petSchemaOneOf = openAPIOneOf.getComponents().getSchemas().get("Pet");
assertTrue(petSchemaOneOf instanceof ComposedSchema);
assertTrue(((ComposedSchema) petSchemaOneOf).getOneOf() != null);

OpenAPI openAPIAllOf = new OpenAPIV3Parser().readLocation("/issue-1157/allOf-example.yaml", auths, options).getOpenAPI();
Schema petSchemaAllOf = openAPIAllOf.getComponents().getSchemas().get("Pet");
assertFalse(petSchemaAllOf instanceof ComposedSchema);
assertTrue(petSchemaAllOf.getProperties() != null);

}

@Test
public void testIssue1161(@Injectable final List<AuthorizationValue> auths) {
String path = "/issue-1161/swagger.yaml";
Expand All @@ -499,8 +523,6 @@ public void testIssue1161(@Injectable final List<AuthorizationValue> auths) {
options.setResolveFully(true);

OpenAPI openAPI = new OpenAPIV3Parser().readLocation(path, auths, options).getOpenAPI();
ResolverFully resolverUtil = new ResolverFully();
resolverUtil.resolveFully(openAPI);

Schema petsSchema = openAPI.getComponents().getSchemas().get("Pets");
Schema colouringsSchema = openAPI.getComponents().getSchemas().get("Colouring");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.0
info:
version: 15.3.0
title: test
paths:
/pets:
get:
description: "Test"
responses:
200:
description: Parameters missing or invalid
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer
Pet:
allOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.0
info:
version: 15.3.0
title: test
paths:
/pets:
get:
description: "Test"
responses:
200:
description: Parameters missing or invalid
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer
Pet:
anyOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
openapi: 3.0.0
info:
version: 15.3.0
title: test
paths:
/pets:
get:
description: "Test"
responses:
200:
description: Parameters missing or invalid
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
Cat:
type: object
properties:
hunts:
type: boolean
age:
type: integer
Pet:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'

0 comments on commit 04e4354

Please sign in to comment.