Skip to content

Commit 63af905

Browse files
gracekarinafrantuma
authored andcommitted
fix for issue when dereferencing OneOf
1 parent 138687c commit 63af905

File tree

4 files changed

+65
-3
lines changed

4 files changed

+65
-3
lines changed

modules/swagger-parser-v3/src/main/java/io/swagger/v3/parser/processors/ExternalRefProcessor.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
149149
for(Schema item : composedSchema.getAllOf()){
150150
if (item.get$ref() != null){
151151
processRefSchema(item,file);
152-
} else if (item.getProperties() != null) {
153-
processProperties(item.getProperties(), file);
152+
} else{
153+
processSchema(item, file);
154154
}
155155
}
156156

@@ -159,6 +159,8 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
159159
if (item.get$ref() != null){
160160
if (item.get$ref() != null){
161161
processRefSchema(item,file);
162+
}else{
163+
processSchema(item, file);
162164
}
163165
}
164166
}
@@ -167,10 +169,11 @@ public String processRefToExternalSchema(String $ref, RefFormat refFormat) {
167169
if (item.get$ref() != null){
168170
if (item.get$ref() != null){
169171
processRefSchema(item,file);
172+
}else{
173+
processSchema(item, file);
170174
}
171175
}
172176
}
173-
174177
}
175178
}
176179
//Loop the properties and recursively call this method;

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ public class OpenAPIV3ParserTest {
8686
protected int serverPort = getDynamicPort();
8787
protected WireMockServer wireMockServer;
8888

89+
90+
@Test
91+
public void testIssueDereferencingComposedSchemaOneOf() {
92+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
93+
ParseOptions options = new ParseOptions();
94+
options.setResolve(true);
95+
SwaggerParseResult parseResult = openApiParser.readLocation("resolverIssue/Beta-1-swagger.yaml", null, options);
96+
OpenAPI openAPI = parseResult.getOpenAPI();
97+
assertNotNull(openAPI.getComponents().getSchemas().get("naNumber"));
98+
assertNotNull(openAPI.getComponents().getSchemas().get("unNumber"));
99+
}
100+
89101
@Test
90102
public void testIssue1621() {
91103
final ParseOptions parseOptions = new ParseOptions();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
openapi: 3.0.3
2+
paths:
3+
/v2/bookings:
4+
post:
5+
tags:
6+
- Booking Request
7+
summary: Post a booking request
8+
description: |
9+
Creates a new booking request
10+
requestBody:
11+
description: Parameters used to create a booking request
12+
required: true
13+
content:
14+
application/json:
15+
schema:
16+
allOf:
17+
- $ref: 'DOCUMENTATION_DOMAIN-3.0.0-domain.yaml#/components/schemas/dangerousGood'
18+
components:
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
openapi: 3.0.3
2+
paths:
3+
components:
4+
schemas:
5+
dangerousGood:
6+
type: object
7+
description: 'Specification for Dangerous Goods'
8+
allOf:
9+
- type: object
10+
oneOf:
11+
- type: object
12+
properties:
13+
unNumber:
14+
"$ref": "#/components/schemas/unNumber"
15+
- type: object
16+
properties:
17+
naNumber:
18+
"$ref": "#/components/schemas/naNumber"
19+
naNumber:
20+
type: string
21+
pattern: "\\d{4}"
22+
description: 'Four-digit number that is assigned to dangerous, hazardous, and
23+
harmful substances. Used for `US`/ `CFR` regularted shipments this is used
24+
instead of `unNumber`'
25+
unNumber:
26+
type: string
27+
pattern: "\\d{4}"
28+
description: 'Four-digit number that is assigned to dangerous, hazardous, and
29+
harmful substances by United Nations'

0 commit comments

Comments
 (0)