Skip to content

Commit c0535ee

Browse files
authored
Merge pull request #858 from ymohdriz/branch_fix855
Fix for issue 855
2 parents f54f20c + 6c45df6 commit c0535ee

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public void resolvePath(PathItem pathItem){
124124
RequestBody refRequestBody = op.getRequestBody();
125125
if (refRequestBody != null){
126126
RequestBody requestBody = refRequestBody.get$ref() != null ? resolveRequestBody(refRequestBody) : refRequestBody;
127+
op.setRequestBody(requestBody);
127128
if (requestBody.getContent() != null) {
128129
Map<String, MediaType> content = requestBody.getContent();
129130
for (String key : content.keySet()) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import io.swagger.v3.oas.models.OpenAPI;
1313
import io.swagger.v3.oas.models.Operation;
1414
import io.swagger.v3.oas.models.PathItem;
15+
import io.swagger.v3.oas.models.media.*;
1516
import io.swagger.v3.oas.models.examples.Example;
1617
import io.swagger.v3.oas.models.media.ArraySchema;
1718
import io.swagger.v3.oas.models.media.ByteArraySchema;
@@ -1522,6 +1523,20 @@ public void readingSpecNodeShouldNotOverQuotingStringExample() throws Exception
15221523
assertEquals("NoQuotePlease", definitions.get("CustomerType").getExample());
15231524
}
15241525

1526+
@Test(description = "Issue 855: Request Body internal refs are not being resolved")
1527+
public void shouldParseRequestBody() {
1528+
ParseOptions parseOptions = new ParseOptions();
1529+
parseOptions.setResolveFully(true);
1530+
OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/issue_855.yaml", null, parseOptions);
1531+
Content actualComponentContent = openAPI.getComponents().getRequestBodies().get("ASinglePet").getContent();
1532+
Content actualPathContent = openAPI.getPaths().get("/adopt").getPost().getRequestBody().getContent();
1533+
Map properties = actualComponentContent.get("application/petstore+json").getSchema().getProperties();
1534+
assertNotNull(properties);
1535+
assertEquals(properties.size(), 2);
1536+
assertNotNull(actualPathContent);
1537+
assertEquals(actualPathContent, actualComponentContent);
1538+
}
1539+
15251540

15261541
private static int getDynamicPort() {
15271542
return new Random().ints(10000, 20000).findFirst().getAsInt();
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
openapi: '3.0.0'
2+
info:
3+
title: Pet Store API
4+
version: '3.0'
5+
6+
paths:
7+
/adopt:
8+
post:
9+
requestBody:
10+
$ref: '#/components/requestBodies/ASinglePet'
11+
responses:
12+
201:
13+
$ref: '#/components/responses/Adopted'
14+
15+
components:
16+
requestBodies:
17+
ASinglePet:
18+
description: Adoption Request
19+
required: true
20+
content:
21+
application/petstore+json:
22+
schema:
23+
$ref: '#/components/schemas/AdoptionRequest'
24+
responses:
25+
Adopted:
26+
description: Pet successfully adopted
27+
content:
28+
application/petstore+json:
29+
schema:
30+
$ref: '#/components/schemas/AdoptionResponse'
31+
32+
schemas:
33+
Pets:
34+
type: object
35+
properties:
36+
pets:
37+
type: array
38+
items:
39+
$ref: '#/components/schemas/Pet'
40+
Pet:
41+
type: object
42+
properties:
43+
name:
44+
type: string
45+
example: Fluffy
46+
AdoptionRequest:
47+
description: Request to adopt a new pet
48+
type: object
49+
required:
50+
- name
51+
- pets
52+
properties:
53+
name:
54+
description: Name pet store
55+
type: string
56+
pets:
57+
$ref: '#/components/schemas/Pets'
58+
AdoptionResponse:
59+
description: Adoption Response
60+
type: object
61+
properties:
62+
string:
63+
description: Uri for the adopted pet
64+
type: string

0 commit comments

Comments
 (0)