Skip to content

Commit b636b6d

Browse files
authored
Merge pull request #1389 from swagger-api/issue1367
Fix and test for Parser cannot process 'allOf' correctly - issue #1367
2 parents 9d20dcb + de0686c commit b636b6d

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@
99
import io.swagger.v3.oas.models.examples.Example;
1010
import io.swagger.v3.oas.models.headers.Header;
1111
import io.swagger.v3.oas.models.links.Link;
12-
import io.swagger.v3.oas.models.media.ArraySchema;
13-
import io.swagger.v3.oas.models.media.ComposedSchema;
14-
import io.swagger.v3.oas.models.media.MapSchema;
15-
import io.swagger.v3.oas.models.media.MediaType;
16-
import io.swagger.v3.oas.models.media.ObjectSchema;
17-
import io.swagger.v3.oas.models.media.Schema;
12+
import io.swagger.v3.oas.models.media.*;
1813
import io.swagger.v3.oas.models.parameters.Parameter;
1914
import io.swagger.v3.oas.models.parameters.RequestBody;
2015
import io.swagger.v3.oas.models.responses.ApiResponse;
@@ -463,6 +458,9 @@ private void aggregateSchemaCombinators(ComposedSchema sourceSchema, Schema targ
463458
}
464459
}
465460
}
461+
if (resolved.getEnum() != null ){
462+
targetSchema.setEnum(resolved.getEnum());
463+
}
466464
if (resolved.getExample() != null) {
467465
examples.add(resolved.getExample());
468466
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,19 @@ public class OpenAPIV3ParserTest {
8383
protected WireMockServer wireMockServer;
8484

8585

86+
@Test
87+
public void testIssue1367() {
88+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
89+
ParseOptions options = new ParseOptions();
90+
options.setResolve(true);
91+
options.setResolveCombinators(true);
92+
options.setResolveFully(true);
93+
options.setFlatten(true);
94+
SwaggerParseResult parseResult = openApiParser.readLocation("issue-1367.yaml", null, options);
95+
OpenAPI openAPI = parseResult.getOpenAPI();
96+
assertTrue(((Schema)openAPI.getComponents().getSchemas().get("TestDTO").getProperties().get("choice")).getEnum() != null);
97+
}
98+
8699
@Test
87100
public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue() {
88101
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
@@ -99,7 +112,6 @@ public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue() {
99112
assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("Inline_response_map200")).getOneOf().get(0).get$ref(),"#/components/schemas/Macaw1");
100113
assertNotNull(openAPI.getComponents().getSchemas().get("Inline_response_map_items404"));
101114
assertEquals(((ComposedSchema)openAPI.getComponents().getSchemas().get("Inline_response_map_items404")).getAnyOf().get(0).get$ref(),"#/components/schemas/Macaw2");
102-
103115
}
104116

105117

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
openapi: 3.0.0
2+
servers:
3+
- url: /subscribed_products/v1.0.1
4+
info:
5+
description: >-
6+
API to get information on services currently subscribed by a specific user
7+
or phone number.
8+
version: 1.0.1
9+
title: Products API definition for the 4th Platform
10+
termsOfService: 'https://www.telefonica.es/es/'
11+
contact:
12+
name: 4th Platform Team
13+
14+
x-fp-apiPrefix: /subscribed_products
15+
tags:
16+
- name: subscribed_products
17+
description: Operations available with products subscribed by a user
18+
paths:
19+
'/TestDTO':
20+
get:
21+
operationId: description
22+
responses:
23+
'200':
24+
description: OK
25+
content:
26+
application/json:
27+
schema:
28+
$ref: '#/components/schemas/TestDTO'
29+
components:
30+
schemas:
31+
TestDTO:
32+
required:
33+
- choice
34+
type: object
35+
properties:
36+
choice:
37+
description: Choice description
38+
allOf:
39+
- $ref: '#/components/schemas/TestEnum'
40+
TestEnum:
41+
type: string
42+
enum:
43+
- One
44+
- Two
45+
- Three

0 commit comments

Comments
 (0)