Skip to content
This repository was archived by the owner on Nov 24, 2022. It is now read-only.

Commit fbe4f4c

Browse files
committed
fix and test for issue swagger-api#1103
1 parent c5404fd commit fbe4f4c

7 files changed

Lines changed: 97 additions & 4 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ private void processParameters(Set<String> ParametersKey, Map<String, Parameter>
190190
for (String parametersName : ParametersKey) {
191191
final Parameter parameter = parameters.get(parametersName);
192192
parameterProcessor.processParameter(parameter);
193+
193194
}
194195
}
195196

@@ -221,13 +222,13 @@ public void processSchemas(Set<String> schemaKeys, Map<String, Schema> schemas)
221222

222223
schemaProcessor.processSchema(model);
223224

224-
//if we process a RefModel here, in the #/definitions table, we want to overwrite it with the referenced value
225+
//if we process a RefModel here, in the #/components/schemas table, we want to overwrite it with the referenced value
225226
if (model.get$ref() != null) {
226227
final String renamedRef = cache.getRenamedRef(originalRef);
227228

228229
if (renamedRef != null) {
229-
//we definitely resolved the referenced and shoved it in the definitions map
230-
// because the referenced model may be in the definitions map, we need to remove old instances
230+
//we definitely resolved the referenced and shoved it in the components map
231+
// because the referenced model may be in the components map, we need to remove old instances
231232
final Schema resolvedModel = schemas.get(renamedRef);
232233

233234
// ensure the reference isn't still in use

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ protected void updateLocalRefs(PathItem path, String pathRef) {
162162
}
163163

164164
protected void updateLocalRefs(ApiResponse response, String pathRef) {
165+
if (response.get$ref() != null){
166+
if(isLocalRef(response.get$ref())) {
167+
response.set$ref(computeLocalRef(response.get$ref(), pathRef));
168+
}
169+
}
165170
if(response.getContent() != null) {
166171
Map<String, MediaType> content = response.getContent();
167172
for (String key: content.keySet()) {
@@ -188,6 +193,11 @@ protected void updateLocalRefs(Example example, String pathRef) {
188193
}
189194

190195
protected void updateLocalRefs(Parameter param, String pathRef) {
196+
if (param.get$ref() != null){
197+
if(isLocalRef(param.get$ref())) {
198+
param.set$ref(computeLocalRef(param.get$ref(), pathRef));
199+
}
200+
}
191201
if(param.getSchema() != null) {
192202
updateLocalRefs(param.getSchema(), pathRef);
193203
}
@@ -204,6 +214,11 @@ protected void updateLocalRefs(Parameter param, String pathRef) {
204214
}
205215

206216
protected void updateLocalRefs(RequestBody body, String pathRef) {
217+
if (body.get$ref() != null){
218+
if(isLocalRef(body.get$ref())) {
219+
body.set$ref(computeLocalRef(body.get$ref(), pathRef));
220+
}
221+
}
207222
if(body.getContent() != null) {
208223
Map<String, MediaType> content = body.getContent();
209224
for (String key: content.keySet()) {

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ public void testResolveFully() throws Exception{
498498
assertEquals(result.getOpenAPI().getComponents().getSchemas().get("OrderRef").getType(),"object");
499499
}
500500

501+
502+
501503
@Test
502504
public void testResolveEmpty(@Injectable final List<AuthorizationValue> auths) throws Exception{
503505
String pathFile = FileUtils.readFileToString(new File("src/test/resources/empty-oas.yaml"));
@@ -558,9 +560,28 @@ public void testInlineModelResolver(@Injectable final List<AuthorizationValue> a
558560
}
559561

560562
@Test
561-
public void test30NoOptions(@Injectable final List<AuthorizationValue> auths) throws Exception{
563+
public void testRemotePathItemIssue1103(@Injectable final List<AuthorizationValue> auths) throws Exception{
564+
565+
566+
OpenAPI result = new OpenAPIV3Parser().read("issue-1103/remote-pathItem-swagger.yaml");
567+
568+
Assert.assertNotNull(result);
569+
Assert.assertNotNull(result.getPaths().get("/Translation/{lang}"));
570+
Assert.assertEquals(result.getPaths().get("/Translation/{lang}").getPut().getParameters().get(0).getName(), "lang");
571+
}
562572

563573

574+
@Test
575+
public void testRemoteParameterIssue1103(@Injectable final List<AuthorizationValue> auths) throws Exception{
576+
577+
OpenAPI result = new OpenAPIV3Parser().read("issue-1103/remote-parameter-swagger.yaml");
578+
Assert.assertNotNull(result);
579+
Assert.assertEquals(result.getPaths().get("/Translation/{lang}").getPut().getParameters().get(0).getName(), "lang");
580+
581+
}
582+
583+
@Test
584+
public void test30NoOptions(@Injectable final List<AuthorizationValue> auths) throws Exception{
564585

565586
String pathFile = FileUtils.readFileToString(new File("src/test/resources/oas3.yaml.template"));
566587
pathFile = pathFile.replace("${dynamicPort}", String.valueOf(this.serverPort));

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/util/OpenAPIDeserializerTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,7 @@ public void readMissingServerObject() throws Exception {
22802280
final OpenAPI openAPI = result.getOpenAPI();
22812281
Assert.assertNotNull(openAPI);
22822282

2283+
22832284
assertEquals(openAPI.getServers().get(0).getUrl(),"/");
22842285
}
22852286

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 1.0.0
4+
title: API Reuse Common Components
5+
description: Definitions of API components to be referred across different API files
6+
components:
7+
pathitems:
8+
Translation:
9+
put:
10+
tags:
11+
- Translation
12+
summary: Set value of this parameter
13+
description: Provide the lookup table for localized strings
14+
parameters:
15+
- $ref: '#/components/parameters/param_lang'
16+
parameters:
17+
param_lang:
18+
name: lang
19+
in: path
20+
description: language - 2-letter abbreviation
21+
required: true
22+
schema:
23+
type: string
24+
enum:
25+
- en
26+
- se
27+
- dk
28+
- fi
29+
- false
30+
- de
31+
- es
32+
- et
33+
- fr
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.0.0
2+
info:
3+
version: "1"
4+
title: Admin Web App Services
5+
description: 'Services'
6+
paths:
7+
'/Translation/{lang}':
8+
put:
9+
tags:
10+
- Translation_Settings
11+
summary: Set value of this parameter
12+
description: Provide the lookup table for localized strings
13+
parameters:
14+
- $ref: 'domain.yaml#/components/parameters/param_lang'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 2.0.0
4+
title: Admin Web App Services
5+
description: 'Services API'
6+
paths:
7+
'/Translation/{lang}':
8+
$ref: './domain.yaml#/components/pathitems/Translation'

0 commit comments

Comments
 (0)