Skip to content

Commit c4f744d

Browse files
mma5997frantuma
authored andcommitted
Added test for #1706
Added a simple spec where there's requestBody and response locally referenced. These will then become inline as per the configured parseOption.
1 parent 18c8c42 commit c4f744d

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,30 @@ public void testIssue1170(@Injectable final List<AuthorizationValue> auths) {
595595
assertTrue(colouringPropertySchema == colouringsSchema);
596596

597597
}
598+
599+
@Test
600+
public void testIssue1706() {
601+
String path = "/issue-1706/SimpleRequestResponseRef.json";
602+
603+
ParseOptions options = new ParseOptions();
604+
options.setResolve(true);
605+
// Added this parseOption to make requestBody inline in the operation resolve processing flow.
606+
options.setResolveRequestBody(true);
607+
608+
OpenAPI openAPI = new OpenAPIV3Parser().readLocation(path, null, options).getOpenAPI();
609+
610+
// RequestBody should be inline
611+
assertTrue(openAPI.getPaths().get("/resource").getPost().getRequestBody().get$ref() == null);
612+
assertTrue(openAPI.getPaths().get("/resource").getPost().getRequestBody().getContent() != null);
613+
assertTrue(openAPI.getPaths().get("/resource").getPost().getRequestBody().getContent().get("application/json").getSchema() instanceof ObjectSchema);
614+
615+
// Responses are already by default made inline in case referenced.
616+
assertTrue(openAPI.getPaths().get("/resource").getPost().getResponses().get("200").get$ref() == null);
617+
assertTrue(openAPI.getPaths().get("/resource").getPost().getResponses().get("200").getContent() != null);
618+
assertTrue(openAPI.getPaths().get("/resource").getPost().getResponses().get("200").getContent().get("application/json").getSchema() instanceof ObjectSchema);
619+
}
620+
621+
598622

599623
@Test
600624
public void selfReferenceTest(@Injectable final List<AuthorizationValue> auths) {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"version": "1.0",
5+
"title": "Resource service",
6+
"description": "Resource service"
7+
},
8+
"servers": [
9+
{
10+
"url": "http://localhost:8088/"
11+
}
12+
],
13+
"paths": {
14+
"/resource": {
15+
"post": {
16+
"summary": "postResource",
17+
"description": "postResource",
18+
"operationId": "post-resource",
19+
"parameters": [],
20+
"requestBody": {
21+
"$ref": "#/components/requestBodies/ResourceBodyPost"
22+
},
23+
"responses": {
24+
"200": {
25+
"$ref": "#/components/responses/ResourceSuccessResponse"
26+
}
27+
}
28+
}
29+
}
30+
},
31+
"components": {
32+
"requestBodies": {
33+
"ResourceBodyPost": {
34+
"content": {
35+
"application/json": {
36+
"schema": {
37+
"type": "object",
38+
"required": [
39+
"rqname"
40+
],
41+
"properties": {
42+
"rqname": {
43+
"type": "string"
44+
},
45+
"rqnumber": {
46+
"type": "integer",
47+
"format": "int32"
48+
},
49+
"rqflag": {
50+
"type": "boolean"
51+
}
52+
}
53+
}
54+
}
55+
}
56+
}
57+
},
58+
"responses": {
59+
"ResourceSuccessResponse": {
60+
"description": "a Element to be returned",
61+
"content": {
62+
"application/json": {
63+
"schema": {
64+
"type": "object",
65+
"required": [
66+
"rname"
67+
],
68+
"properties": {
69+
"rname": {
70+
"type": "string"
71+
},
72+
"rnumber": {
73+
"type": "integer",
74+
"format": "int32"
75+
},
76+
"rflag": {
77+
"type": "boolean"
78+
}
79+
}
80+
}
81+
}
82+
}
83+
}
84+
},
85+
"schemas": {}
86+
}
87+
}

0 commit comments

Comments
 (0)