Skip to content

Commit

Permalink
Merge pull request #1389 from swagger-api/issue1367
Browse files Browse the repository at this point in the history
Fix and test for Parser cannot process 'allOf' correctly - issue #1367
  • Loading branch information
gracekarina authored Jun 19, 2020
2 parents 9d20dcb + de0686c commit b636b6d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
import io.swagger.v3.oas.models.examples.Example;
import io.swagger.v3.oas.models.headers.Header;
import io.swagger.v3.oas.models.links.Link;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.ComposedSchema;
import io.swagger.v3.oas.models.media.MapSchema;
import io.swagger.v3.oas.models.media.MediaType;
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.*;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.responses.ApiResponse;
Expand Down Expand Up @@ -463,6 +458,9 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ
}
}
}
if (resolved.getEnum() != null ){
targetSchema.setEnum(resolved.getEnum());
}
if (resolved.getExample() != null) {
examples.add(resolved.getExample());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ public class OpenAPIV3ParserTest {
protected WireMockServer wireMockServer;


@Test
public void testIssue1367() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveCombinators(true);
options.setResolveFully(true);
options.setFlatten(true);
SwaggerParseResult parseResult = openApiParser.readLocation("issue-1367.yaml", null, options);
OpenAPI openAPI = parseResult.getOpenAPI();
assertTrue(((Schema)openAPI.getComponents().getSchemas().get("TestDTO").getProperties().get("choice")).getEnum() != null);
}

@Test
public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue() {
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
Expand All @@ -99,7 +112,6 @@ public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue() {
assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("Inline_response_map200")).getOneOf().get(0).get$ref(),"#/components/schemas/Macaw1");
assertNotNull(openAPI.getComponents().getSchemas().get("Inline_response_map_items404"));
assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("Inline_response_map_items404")).getAnyOf().get(0).get$ref(),"#/components/schemas/Macaw2");

}


Expand Down
45 changes: 45 additions & 0 deletions modules/swagger-parser-v3/src/test/resources/issue-1367.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
openapi: 3.0.0
servers:
- url: /subscribed_products/v1.0.1
info:
description: >-
API to get information on services currently subscribed by a specific user
or phone number.
version: 1.0.1
title: Products API definition for the 4th Platform
termsOfService: 'https://www.telefonica.es/es/'
contact:
name: 4th Platform Team
email: [email protected]
x-fp-apiPrefix: /subscribed_products
tags:
- name: subscribed_products
description: Operations available with products subscribed by a user
paths:
'/TestDTO':
get:
operationId: description
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/TestDTO'
components:
schemas:
TestDTO:
required:
- choice
type: object
properties:
choice:
description: Choice description
allOf:
- $ref: '#/components/schemas/TestEnum'
TestEnum:
type: string
enum:
- One
- Two
- Three

0 comments on commit b636b6d

Please sign in to comment.