Skip to content

Commit fce6d9e

Browse files
gracekarinafrantuma
authored andcommitted
oas 3.1 - test for siblings ref ticket
1 parent ead8af7 commit fce6d9e

File tree

3 files changed

+85
-18
lines changed

3 files changed

+85
-18
lines changed

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,6 @@ public PathItem getPathItem(ObjectNode obj, String location, ParseResult result)
956956
if (StringUtils.isNotBlank(value)) {
957957
pathItem.setSummary(value);
958958
}
959-
960959
value = getString("description", obj, false, location, result);
961960
if (StringUtils.isNotBlank(value)) {
962961
pathItem.setDescription(value);
@@ -2171,9 +2170,7 @@ public Header getHeader(ObjectNode headerNode, String location, ParseResult resu
21712170
return header;
21722171
}
21732172

2174-
21752173
public Object getAnyExample(String nodeKey, ObjectNode node, String location, ParseResult result) {
2176-
//TODO: Examples now allows Ref
21772174
JsonNode example = node.get(nodeKey);
21782175
if (example != null) {
21792176
if (example.getNodeType().equals(JsonNodeType.STRING)) {
@@ -2246,7 +2243,6 @@ public SecurityScheme getSecurityScheme(ObjectNode node, String location, ParseR
22462243
if (node == null) {
22472244
return null;
22482245
}
2249-
22502246
SecurityScheme securityScheme = new SecurityScheme();
22512247

22522248
JsonNode ref = node.get("$ref");
@@ -3137,18 +3133,6 @@ public Example getExample(ObjectNode node, String location, ParseResult result)
31373133
} else {
31383134
example.set$ref(ref.textValue());
31393135
}
3140-
if (result.isOpenapi31()) {
3141-
String desc = getString("summary", node, false, location, result);
3142-
if (StringUtils.isNotBlank(desc)) {
3143-
example.setSummary(desc);
3144-
}
3145-
}
3146-
if (result.isOpenapi31()) {
3147-
String desc = getString("description", node, false, location, result);
3148-
if (StringUtils.isNotBlank(desc)) {
3149-
example.setDescription(desc);
3150-
}
3151-
}
31523136
return example;
31533137
} else {
31543138
result.invalidType(location, "$ref", "string", node);
@@ -3279,8 +3263,7 @@ public ApiResponse getResponse(ObjectNode node, String location, ParseResult res
32793263
apiResponse.set$ref(ref.textValue());
32803264
}
32813265
if(result.isOpenapi31()){
3282-
String value = getString("summary", node, false, location, result);
3283-
value = getString("description", node, false, location, result);
3266+
String value = getString("description", node, false, location, result);
32843267
if (StringUtils.isNotBlank(value)) {
32853268
apiResponse.setDescription(value);
32863269
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,42 @@ public void testReservedExtensionsOaiAuthorTrue() {
197197
assertFalse(result.getMessages().contains("attribute x-oas-internal is reserved by The OpenAPI Initiative"));
198198
assertFalse(result.getMessages().contains("attribute x-oai-extension is reserved by The OpenAPI Initiative"));
199199
}
200+
201+
@Test
202+
public void testSiblingsReferenceObjects() {
203+
ParseOptions options = new ParseOptions();
204+
options.setOaiAuthor(true);
205+
SwaggerParseResult result = new OpenAPIV3Parser().readLocation( "3.1.0/siblings31.yaml", null, options);
206+
OpenAPI openAPI = result.getOpenAPI();
207+
assertNotNull(openAPI);
208+
209+
//PathItems
210+
assertTrue(openAPI.getPaths().get("/pets").get$ref() != null
211+
&& openAPI.getPaths().get("/pets").getDescription() != null
212+
&& openAPI.getPaths().get("/pets").getSummary() != null);
213+
214+
//Parameters
215+
assertTrue(openAPI.getPaths().get("/pets/{petId}").getGet().getParameters().get(0).get$ref() != null
216+
&& openAPI.getPaths().get("/pets/{petId}").getGet().getParameters().get(0).getDescription() != null);
217+
218+
//Responses
219+
assertTrue(openAPI.getPaths().get("/pets/{petId}").getGet().getResponses().get("200").get$ref() != null
220+
&& openAPI.getPaths().get("/pets/{petId}").getGet().getResponses().get("200").getDescription() != null);
221+
222+
//RequestBody
223+
assertTrue(openAPI.getPaths().get("/pets/requestBody").getPost().getRequestBody().get$ref() != null
224+
&& openAPI.getPaths().get("/pets/requestBody").getPost().getRequestBody().getDescription() != null);
225+
226+
//Headers
227+
assertTrue(openAPI.getPaths().get("/pets/requestBody").getPost().getResponses().get("200").getHeaders().get("X-Rate-Limit").get$ref() != null
228+
&& openAPI.getPaths().get("/pets/requestBody").getPost().getResponses().get("200").getHeaders().get("X-Rate-Limit").getDescription() != null);
229+
230+
//Links
231+
assertTrue(openAPI.getPaths().get("/pets/requestBody").getPost().getResponses().get("200").getLinks().get("userRepository").get$ref() != null
232+
&& openAPI.getPaths().get("/pets/requestBody").getPost().getResponses().get("200").getLinks().get("userRepository").getDescription() != null);
233+
234+
//SecuritySchemes
235+
assertTrue(openAPI.getComponents().getSecuritySchemes().get("api_key").get$ref() != null
236+
&& openAPI.getComponents().getSecuritySchemes().get("api_key").getDescription() != null);
237+
}
200238
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
openapi: "3.1.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
paths:
6+
/pets:
7+
$ref: "#/components/pathItems/Pets"
8+
summary: List all pets
9+
description: description
10+
/pets/{petId}:
11+
get:
12+
summary: Info for a specific pet
13+
operationId: showPetById
14+
security:
15+
- apiKey: [ ]
16+
tags:
17+
- pets
18+
parameters:
19+
- $ref: "#/components/parameters/Pets"
20+
description: The id of the pet to retrieve
21+
responses:
22+
"200":
23+
$ref: "#/components/responses/Pets"
24+
description: Expected response to a valid request
25+
/pets/requestBody:
26+
post:
27+
description: It gets pets
28+
responses:
29+
'200':
30+
description: successful operation
31+
headers:
32+
X-Rate-Limit:
33+
$ref: "#/components/headers/Pets"
34+
description: header sibling description
35+
links:
36+
userRepository:
37+
$ref: '#/components/links/userRepository'
38+
description: link sibling description
39+
requestBody:
40+
$ref: "#/components/requestBodies/Pets"
41+
description: request body description
42+
components:
43+
securitySchemes:
44+
api_key:
45+
$ref: "#/components/securitySchemes/security"
46+
description: This is another description

0 commit comments

Comments
 (0)