Skip to content

Commit 0541677

Browse files
authored
Merge pull request #893 from r-sreesaran/branch_test
added fix for issue 889
2 parents 918c0cb + 7c9125f commit 0541677

File tree

3 files changed

+168
-0
lines changed

3 files changed

+168
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,18 @@ public List<Tag> getTagList(ArrayNode obj, String location, ParseResult result)
293293
return null;
294294
}
295295
List<Tag> tags = new ArrayList<>();
296+
Set<String> tagsTracker = new HashSet<>();
296297
for (JsonNode item : obj) {
297298
if (item.getNodeType().equals(JsonNodeType.OBJECT)) {
298299
Tag tag = getTag((ObjectNode) item, location, result);
299300
if (tag != null) {
300301
tags.add(tag);
302+
303+
if(tagsTracker.contains((String)tag.getName())) {
304+
result.uniqueTags(location,tag.getName());
305+
}
306+
307+
tagsTracker.add(tag.getName());
301308
}
302309
}
303310
}
@@ -2676,6 +2683,7 @@ protected static class ParseResult {
26762683
private Map<Location, String> invalidType = new LinkedHashMap<>();
26772684
private List<Location> missing = new ArrayList<>();
26782685
private List<Location> unique = new ArrayList<>();
2686+
private List<Location> uniqueTags = new ArrayList<>();
26792687

26802688
public ParseResult() {
26812689
}
@@ -2696,6 +2704,8 @@ public void unique(String location, String key) {
26962704
unique.add(new Location(location, key));
26972705
}
26982706

2707+
public void uniqueTags(String location, String key) {uniqueTags.add(new Location(location,key));}
2708+
26992709
public void invalidType(String location, String key, String expectedType, JsonNode value) {
27002710
invalidType.put(new Location(location, key), expectedType);
27012711
}
@@ -2735,6 +2745,11 @@ public List<String> getMessages() {
27352745
String message = "attribute " + location + l.key + " is repeated";
27362746
messages.add(message);
27372747
}
2748+
for (Location l : uniqueTags) {
2749+
String location = l.location.equals("") ? "" : l.location + ".";
2750+
String message = "attribute " + location + l.key + " is repeated";
2751+
messages.add(message);
2752+
}
27382753
return messages;
27392754
}
27402755
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ public void testSimple() {
6464
assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");
6565
}
6666

67+
68+
@Test
69+
public void testIssue887() {
70+
ParseOptions options = new ParseOptions();
71+
SwaggerParseResult result = new OpenAPIParser().readLocation("apiWithMultipleTags.json", null, null);
72+
System.out.println(result.getMessages());
73+
assertNotNull(result);
74+
assertNotNull(result.getOpenAPI());
75+
assertEquals(result.getMessages().get(0), "attribute tags.sample is repeated");
76+
}
77+
6778
@Test
6879
public void testIssue768() {
6980
ParseOptions options = new ParseOptions();
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Sample API",
5+
"description": "Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.",
6+
"version": "0.1.9"
7+
},
8+
"servers": [
9+
{
10+
"url": "http://localhost:5555/rest/RestNativeService",
11+
"description": "a service that accepts anything"
12+
}
13+
],
14+
"tags":[
15+
{"name":"sample"},
16+
{"name":"sample"}
17+
],
18+
"paths": {
19+
"/getTimeAfterJson/{time}": {
20+
"post": {
21+
22+
"security" : [{"OpenID":["read"]}],
23+
"parameters": [
24+
{
25+
"in": "path",
26+
"name": "time",
27+
"content": {
28+
"application/json": {
29+
"schema": {
30+
"type": "integer"
31+
32+
}
33+
}
34+
}
35+
},
36+
37+
{
38+
"in": "cookie",
39+
"name": "debug",
40+
"schema": {
41+
"type": "integer",
42+
"enum": [
43+
0,
44+
1
45+
],
46+
"default": 0
47+
},
48+
"required":true
49+
},
50+
{
51+
"in": "cookie",
52+
"name": "csrftoken",
53+
"schema": {
54+
"type": "string"
55+
},
56+
"required":true
57+
}
58+
],
59+
"requestBody": {
60+
"content": {
61+
"application/json": {
62+
"schema": {
63+
"allOf": [
64+
{
65+
"$ref": "#/components/schemas/temp"
66+
},
67+
{
68+
"$ref": "#/components/schemas/temp1"
69+
}
70+
]
71+
}
72+
}
73+
}
74+
},
75+
"responses": {
76+
"200": {
77+
"description": "Updated"
78+
}
79+
}
80+
}
81+
}
82+
},
83+
"components": {
84+
"securitySchemes":{
85+
"BasicAuth": {
86+
"type": "http",
87+
"scheme": "basic"
88+
},
89+
"BearerAuth": {
90+
"type": "http",
91+
"scheme": "bearer"
92+
},
93+
"ApiKeyAuth": {
94+
"type": "apiKey",
95+
"in": "header",
96+
"name": "X-API-Key"
97+
},
98+
"OAuth2": {
99+
"type": "oauth2",
100+
"flows": {
101+
"authorizationCode": {
102+
"refreshUrl":"http://localhost:555",
103+
"authorizationUrl": "https://example.com/oauth/authorize",
104+
"tokenUrl": "https://example.com/oauth/token",
105+
"scopes": {
106+
"read": "Grants read access",
107+
"write": "Grants write access",
108+
"admin": "Grants access to admin operations"
109+
}
110+
}
111+
}
112+
}
113+
},
114+
"schemas": {
115+
"temp": {
116+
"type": "object",
117+
"properties": {
118+
"bool1": {
119+
"type": "boolean"
120+
},
121+
"timetype": {
122+
"type": "string",
123+
"enum": [
124+
"nanoseconds",
125+
"milliseconds"
126+
]
127+
}
128+
},
129+
"required":["bool1","timetype"]
130+
},
131+
"temp1": {
132+
"properties":{
133+
"int":{
134+
"type": "integer"
135+
}
136+
}
137+
138+
}
139+
}
140+
141+
}
142+
}

0 commit comments

Comments
 (0)