Skip to content

Commit a17b2b7

Browse files
authored
Merge pull request #1218 from swagger-api/codegen-issue-9773
fixing remote schema ref resolving in referenced request body
2 parents d9fa744 + 91508ef commit a17b2b7

File tree

6 files changed

+88
-1
lines changed

6 files changed

+88
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ public String processRefToExternalRequestBody(String $ref, RefFormat refFormat)
322322
} else {
323323
processRefToExternalRequestBody(file + body.get$ref(), RefFormat.RELATIVE);
324324
}
325+
}else if(body.getContent() != null){
326+
processRefContent(body.getContent(), $ref);
325327
}
326328
}
327329

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
@@ -66,6 +66,18 @@ public class OpenAPIV3ParserTest {
6666
protected int serverPort = getDynamicPort();
6767
protected WireMockServer wireMockServer;
6868

69+
@Test
70+
public void testCodegenIssue9773() {
71+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
72+
ParseOptions options = new ParseOptions();
73+
options.setResolve(true);
74+
options.setFlatten(true);
75+
SwaggerParseResult parseResult = openApiParser.readLocation("codegen-issue-9773/openapi.yaml", null, options);
76+
77+
OpenAPI openAPI = parseResult.getOpenAPI();
78+
assertNotNull(openAPI.getComponents().getSchemas().get("Foo"));
79+
}
80+
6981
@Test
7082
public void testIssueResolveCallBacks() {
7183
ParseOptions options = new ParseOptions();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
components:
2+
requestBodies:
3+
RequestBody1:
4+
required: true
5+
content:
6+
application/json:
7+
schema:
8+
$ref: '#/components/schemas/Foo'
9+
10+
schemas:
11+
Foo:
12+
type: object
13+
properties:
14+
foo:
15+
type: string
16+
example: bar
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openapi: 3.0.2
2+
info:
3+
title: 'Codegen test: requestBody with an external $ref'
4+
version: 0.0.0
5+
paths:
6+
/foo:
7+
post:
8+
requestBody:
9+
$ref: './domain.yaml#/components/requestBodies/RequestBody1'
10+
responses:
11+
'200':
12+
description: OK
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: spec2
5+
components:
6+
schemas:
7+
FlowDescription:
8+
type: string
9+
EthFlowDescription:
10+
type: object
11+
properties:
12+
fDesc:
13+
$ref: '#/components/schemas/FlowDescription'
14+
fDir:
15+
$ref: 'spec1.yaml#/components/schemas/FlowDirection'

modules/swagger-parser-v3/src/test/resources/remote_references/remote_requestBody.yaml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,34 @@ requestBodies:
55
application/json:
66
description: Pet object that needs to be added to the store
77
schema:
8-
"$ref": "#/components/schemas/Pet"
8+
Pet:
9+
type: object
10+
required:
11+
- name
12+
- photoUrls
13+
properties:
14+
id:
15+
type: integer
16+
format: int64
17+
name:
18+
type: string
19+
example: doggie
20+
photoUrls:
21+
type: array
22+
xml:
23+
name: photoUrl
24+
wrapped: true
25+
items:
26+
type: string
27+
tags:
28+
type: array
29+
xml:
30+
name: tag
31+
wrapped: true
32+
status:
33+
type: string
34+
description: pet status in the store
35+
enum:
36+
- available
37+
- pending
38+
- sold

0 commit comments

Comments
 (0)