Skip to content

Commit c2f024f

Browse files
committed
added fix for issue 959
1 parent d020ad2 commit c2f024f

File tree

3 files changed

+232
-1
lines changed

3 files changed

+232
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,8 @@ public Map<String, Parameter> getParameters(ObjectNode obj, String location, Par
13651365
return null;
13661366
}
13671367
Map<String, Parameter> parameters = new LinkedHashMap<>();
1368+
Set<String> filter = new HashSet<>();
1369+
Parameter parameter=null;
13681370

13691371
Set<String> parameterKeys = getKeys(obj);
13701372
for(String parameterName : parameterKeys) {
@@ -1377,12 +1379,15 @@ public Map<String, Parameter> getParameters(ObjectNode obj, String location, Par
13771379
if (parameterValue.getNodeType().equals(JsonNodeType.OBJECT)) {
13781380
ObjectNode parameterObj = (ObjectNode) parameterValue;
13791381
if(parameterObj != null) {
1380-
Parameter parameter = getParameter(parameterObj, String.format("%s.%s", location, parameterName), result);
1382+
parameter = getParameter(parameterObj, String.format("%s.%s", location, parameterName), result);
13811383
if (parameter != null) {
13821384
parameters.put(parameterName, parameter);
13831385
}
13841386
}
13851387
}
1388+
if(!filter.add(parameter.getName()+"#"+parameter.getIn())) {
1389+
result.warning(location,"There are duplicate parameter values");
1390+
}
13861391
}
13871392
return parameters;
13881393
}
@@ -1401,6 +1406,13 @@ public List<Parameter> getParameterList(ArrayNode obj, String location, ParseRes
14011406
}
14021407
}
14031408
}
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+
}
14041416
return parameters;
14051417
}
14061418

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,10 @@ public void testIssue879() {
462462
assertEquals(ref, "#/components/callbacks/callbackEvent");
463463
}
464464

465+
@Test
466+
public void testIssue959() {
467+
OpenAPIParser openAPIParser = new OpenAPIParser();
468+
SwaggerParseResult result = openAPIParser.readLocation("issue959.json",null,null);
469+
assertEquals(result.getMessages().size(),2);
470+
}
465471
}
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
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+
"get": {
23+
"summary": "List all pets",
24+
"operationId": "listPets",
25+
"tags": [
26+
"pets"
27+
],
28+
"parameters": [
29+
{
30+
"name": "limit",
31+
"in": "query",
32+
"description": "How many items to return at one time (max 100)",
33+
"required": false,
34+
"schema": {
35+
"type": "integer",
36+
"format": "int32"
37+
}
38+
}
39+
],
40+
"responses": {
41+
"200": {
42+
"description": "A paged array of pets",
43+
"headers": {
44+
"x-next": {
45+
"description": "A link to the next page of responses",
46+
"schema": {
47+
"type": "string"
48+
}
49+
}
50+
},
51+
"content": {
52+
"application/json": {
53+
"schema": {
54+
"$ref": "#/components/schemas/Pets"
55+
}
56+
}
57+
}
58+
},
59+
"default": {
60+
"description": "unexpected error",
61+
"content": {
62+
"application/json": {
63+
"schema": {
64+
"$ref": "#/components/schemas/Error"
65+
}
66+
}
67+
}
68+
}
69+
}
70+
},
71+
"post": {
72+
"summary": "Create a pet",
73+
"operationId": "createPets",
74+
"tags": [
75+
"pets"
76+
],
77+
"responses": {
78+
"201": {
79+
"description": "Null response"
80+
},
81+
"default": {
82+
"description": "unexpected error",
83+
"content": {
84+
"application/json": {
85+
"schema": {
86+
"$ref": "#/components/schemas/Error"
87+
}
88+
}
89+
}
90+
}
91+
}
92+
}
93+
},
94+
"/pets/{petId}": {
95+
"get": {
96+
"summary": "Info for a specific pet",
97+
"operationId": "showPetById",
98+
"tags": [
99+
"pets"
100+
],
101+
"parameters": [
102+
{
103+
"name": "petId",
104+
"in": "path",
105+
"required": true,
106+
"description": "The id of the pet to retrieve",
107+
"schema": {
108+
"type": "string"
109+
}
110+
},
111+
{
112+
"name":"petId",
113+
"in":"path",
114+
"required": true
115+
116+
}
117+
],
118+
"responses": {
119+
"200": {
120+
"description": "Expected response to a valid request",
121+
"content": {
122+
"application/json": {
123+
"schema": {
124+
"$ref": "#/components/schemas/Pets"
125+
}
126+
}
127+
}
128+
},
129+
"default": {
130+
"description": "unexpected error",
131+
"content": {
132+
"application/json": {
133+
"schema": {
134+
"$ref": "#/components/schemas/Error"
135+
}
136+
}
137+
}
138+
}
139+
}
140+
}
141+
}
142+
},
143+
"components": {
144+
"schemas": {
145+
"Pet": {
146+
"required": [
147+
"id",
148+
"name"
149+
],
150+
"properties": {
151+
"id": {
152+
"type": "integer",
153+
"format": "int64"
154+
},
155+
"name": {
156+
"type": "string"
157+
},
158+
"tag": {
159+
"type": "string"
160+
}
161+
}
162+
},
163+
"Pets": {
164+
"type": "array",
165+
"items": {
166+
"$ref": "#/components/schemas/Pet"
167+
}
168+
},
169+
"Error": {
170+
"required": [
171+
"code",
172+
"message"
173+
],
174+
"properties": {
175+
"code": {
176+
"type": "integer",
177+
"format": "int32"
178+
},
179+
"message": {
180+
"type": "string"
181+
}
182+
}
183+
}
184+
},
185+
"parameters": {
186+
"offsetParam": {
187+
"name": "offset",
188+
"in": "query",
189+
"description": "Number of items to skip before returning the results.",
190+
"required": false,
191+
"schema": {
192+
"type": "integer",
193+
"format": "int32",
194+
"minimum": 0,
195+
"default": 0
196+
}
197+
},
198+
"limitParam": {
199+
"name": "offset",
200+
"in": "query",
201+
"description": "Maximum number of items to return.",
202+
"required": false,
203+
"schema": {
204+
"type": "integer",
205+
"format": "int32",
206+
"minimum": 1,
207+
"maximum": 100,
208+
"default": 20
209+
}
210+
}
211+
}
212+
}
213+
}

0 commit comments

Comments
 (0)