Skip to content

Commit bdd359e

Browse files
authored
Merge pull request #960 from r-sreesaran/master
added fix for issue 959
2 parents a876a6f + 0d92dc3 commit bdd359e

File tree

4 files changed

+465
-1
lines changed

4 files changed

+465
-1
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,6 +1367,8 @@ public Map<String, Parameter> getParameters(ObjectNode obj, String location, Par
13671367
return null;
13681368
}
13691369
Map<String, Parameter> parameters = new LinkedHashMap<>();
1370+
Set<String> filter = new HashSet<>();
1371+
Parameter parameter=null;
13701372

13711373
Set<String> parameterKeys = getKeys(obj);
13721374
for(String parameterName : parameterKeys) {
@@ -1379,12 +1381,13 @@ public Map<String, Parameter> getParameters(ObjectNode obj, String location, Par
13791381
if (parameterValue.getNodeType().equals(JsonNodeType.OBJECT)) {
13801382
ObjectNode parameterObj = (ObjectNode) parameterValue;
13811383
if(parameterObj != null) {
1382-
Parameter parameter = getParameter(parameterObj, String.format("%s.%s", location, parameterName), result);
1384+
parameter = getParameter(parameterObj, String.format("%s.%s", location, parameterName), result);
13831385
if (parameter != null) {
13841386
parameters.put(parameterName, parameter);
13851387
}
13861388
}
13871389
}
1390+
13881391
}
13891392
return parameters;
13901393
}
@@ -1403,6 +1406,13 @@ public List<Parameter> getParameterList(ArrayNode obj, String location, ParseRes
14031406
}
14041407
}
14051408
}
1409+
Set<String> filter = new HashSet<>();
1410+
1411+
for(Parameter param:parameters) {
1412+
if(!filter.add(param.getName()+"#"+param.getIn())) {
1413+
result.warning(location,"There are duplicate parameter values");
1414+
}
1415+
}
14061416
return parameters;
14071417
}
14081418

modules/swagger-parser/src/test/java/io/swagger/parser/OpenAPIParserTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,4 +470,16 @@ public void testIssue879() {
470470
assertEquals(ref, "#/components/callbacks/callbackEvent");
471471
}
472472

473+
@Test
474+
public void testIssue959() {
475+
OpenAPIParser openAPIParser = new OpenAPIParser();
476+
SwaggerParseResult result = openAPIParser.readLocation("issue959.json",null,null);
477+
assertEquals(result.getMessages().get(0),"attribute paths.'/pets/{petId}'(get).parameters.There are duplicate parameter values");
478+
479+
result = openAPIParser.readLocation("issue959PathLevelDuplication.json",null,null);
480+
assertEquals(result.getMessages().get(0),"attribute paths.'/pets'.There are duplicate parameter values");
481+
482+
}
483+
473484
}
485+
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"license": {
7+
"name": "MIT"
8+
}
9+
},
10+
"servers": [
11+
{
12+
"url": "http://petstore.swagger.io/v1"
13+
}
14+
],
15+
"tags" : [
16+
{"name":"pet" ,
17+
"description":"+ data"
18+
}
19+
],
20+
"paths": {
21+
"/pets": {
22+
"parameters": [
23+
{
24+
"name": "limit",
25+
"in": "query",
26+
"description": "How many items to return at one time (max 100)",
27+
"required": false,
28+
"schema": {
29+
"type": "integer",
30+
"format": "int32"
31+
}
32+
}
33+
],
34+
"get": {
35+
"summary": "List all pets",
36+
"operationId": "listPets",
37+
"tags": [
38+
"pets"
39+
],
40+
"parameters": [
41+
{
42+
"name": "limit",
43+
"in": "query",
44+
"description": "How many items to return at one time (max 100)",
45+
"required": false,
46+
"schema": {
47+
"type": "integer",
48+
"format": "int32"
49+
}
50+
}
51+
],
52+
"responses": {
53+
"200": {
54+
"description": "A paged array of pets",
55+
"headers": {
56+
"x-next": {
57+
"description": "A link to the next page of responses",
58+
"schema": {
59+
"type": "string"
60+
}
61+
}
62+
},
63+
"content": {
64+
"application/json": {
65+
"schema": {
66+
"$ref": "#/components/schemas/Pets"
67+
}
68+
}
69+
}
70+
},
71+
"default": {
72+
"description": "unexpected error",
73+
"content": {
74+
"application/json": {
75+
"schema": {
76+
"$ref": "#/components/schemas/Error"
77+
}
78+
}
79+
}
80+
}
81+
}
82+
},
83+
"post": {
84+
"summary": "Create a pet",
85+
"operationId": "createPets",
86+
"tags": [
87+
"pets"
88+
],
89+
"responses": {
90+
"201": {
91+
"description": "Null response"
92+
},
93+
"default": {
94+
"description": "unexpected error",
95+
"content": {
96+
"application/json": {
97+
"schema": {
98+
"$ref": "#/components/schemas/Error"
99+
}
100+
}
101+
}
102+
}
103+
}
104+
}
105+
},
106+
"/pets/{petId}": {
107+
"get": {
108+
"summary": "Info for a specific pet",
109+
"operationId": "showPetById",
110+
"tags": [
111+
"pets"
112+
],
113+
"parameters": [
114+
{
115+
"name": "petId",
116+
"in": "path",
117+
"required": true,
118+
"description": "The id of the pet to retrieve",
119+
"schema": {
120+
"type": "string"
121+
}
122+
},
123+
{
124+
"name":"petId",
125+
"in":"path",
126+
"required": true
127+
128+
}
129+
],
130+
"responses": {
131+
"200": {
132+
"description": "Expected response to a valid request",
133+
"content": {
134+
"application/json": {
135+
"schema": {
136+
"$ref": "#/components/schemas/Pets"
137+
}
138+
}
139+
}
140+
},
141+
"default": {
142+
"description": "unexpected error",
143+
"content": {
144+
"application/json": {
145+
"schema": {
146+
"$ref": "#/components/schemas/Error"
147+
}
148+
}
149+
}
150+
}
151+
}
152+
}
153+
}
154+
},
155+
"components": {
156+
"schemas": {
157+
"Pet": {
158+
"required": [
159+
"id",
160+
"name"
161+
],
162+
"properties": {
163+
"id": {
164+
"type": "integer",
165+
"format": "int64"
166+
},
167+
"name": {
168+
"type": "string"
169+
},
170+
"tag": {
171+
"type": "string"
172+
}
173+
}
174+
},
175+
"Pets": {
176+
"type": "array",
177+
"items": {
178+
"$ref": "#/components/schemas/Pet"
179+
}
180+
},
181+
"Error": {
182+
"required": [
183+
"code",
184+
"message"
185+
],
186+
"properties": {
187+
"code": {
188+
"type": "integer",
189+
"format": "int32"
190+
},
191+
"message": {
192+
"type": "string"
193+
}
194+
}
195+
}
196+
},
197+
"parameters": {
198+
"offsetParam": {
199+
"name": "offset",
200+
"in": "query",
201+
"description": "Number of items to skip before returning the results.",
202+
"required": false,
203+
"schema": {
204+
"type": "integer",
205+
"format": "int32",
206+
"minimum": 0,
207+
"default": 0
208+
}
209+
},
210+
"limitParam": {
211+
"name": "offset",
212+
"in": "query",
213+
"description": "Maximum number of items to return.",
214+
"required": false,
215+
"schema": {
216+
"type": "integer",
217+
"format": "int32",
218+
"minimum": 1,
219+
"maximum": 100,
220+
"default": 20
221+
}
222+
}
223+
}
224+
}
225+
}

0 commit comments

Comments
 (0)