Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix and test for Parser cannot process 'allOf' correctly - issue #1367 #1389

Merged
merged 1 commit into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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: 4pf@tid.es
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