Skip to content

Commit 2929e43

Browse files
authored
Merge pull request #896 from r-sreesaran/branch_test
Fix for issue 895
2 parents 3ee7b0c + d4270bc commit 2929e43

File tree

4 files changed

+388
-703
lines changed

4 files changed

+388
-703
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,12 @@ public License getLicense(ObjectNode node, String location, ParseResult result)
813813

814814
value = getString("url", node, false, location, result);
815815
if(StringUtils.isNotBlank(value)) {
816+
try {
817+
new URL(value);
818+
}
819+
catch (Exception e) {
820+
result.warning(location,value);
821+
}
816822
license.setUrl(value);
817823
}
818824

@@ -844,6 +850,12 @@ public Contact getContact(ObjectNode node, String location, ParseResult result)
844850

845851
value = getString("url", node, false, location, result);
846852
if(StringUtils.isNotBlank(value)) {
853+
try {
854+
new URL(value);
855+
}
856+
catch (Exception e) {
857+
result.warning(location,value);
858+
}
847859
contact.setUrl(value);
848860
}
849861

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public void testIssue887() {
7575
assertEquals(result.getMessages().get(0), "attribute tags.sample is repeated");
7676
}
7777

78+
@Test
79+
public void testIssue895() {
80+
SwaggerParseResult result = new OpenAPIParser().readLocation("issue895.yaml", null, null);
81+
assertNotNull(result);
82+
assertNotNull(result.getOpenAPI());
83+
assertEquals(result.getMessages().get(0),"attribute info.contact.test");
84+
assertEquals(result.getMessages().get(1),"attribute info.license.test1");
85+
86+
}
87+
7888
@Test
7989
public void testIssue892() {
8090
SwaggerParseResult result = new OpenAPIParser().readLocation("issue892-main.yaml", null, null);
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"contact": {
7+
"name": "API Support",
8+
"url": "test",
9+
"email": "[email protected]"
10+
},
11+
"license": {
12+
"name": "Apache 2.0",
13+
"url": "test1"
14+
}
15+
},
16+
"servers": [
17+
{
18+
"url": "http://petstore.swagger.io/v1"
19+
}
20+
],
21+
"tags" : [
22+
{"name":"pet" ,
23+
"description":"+ data"
24+
}
25+
],
26+
"paths": {
27+
"/pets": {
28+
"get": {
29+
"summary": "List all pets",
30+
"operationId": "listPets",
31+
"tags": [
32+
"pets"
33+
],
34+
"parameters": [
35+
{
36+
"name": "limit",
37+
"in": "query",
38+
"description": "How many items to return at one time (max 100)",
39+
"required": false,
40+
"schema": {
41+
"type": "integer",
42+
"format": "int32"
43+
}
44+
}
45+
],
46+
"responses": {
47+
"200": {
48+
"description": "A paged array of pets",
49+
"headers": {
50+
"x-next": {
51+
"description": "A link to the next page of responses",
52+
"schema": {
53+
"type": "string"
54+
}
55+
}
56+
},
57+
"content": {
58+
"application/json": {
59+
"schema": {
60+
"$ref": "#/components/schemas/Pets"
61+
}
62+
}
63+
}
64+
},
65+
"default": {
66+
"description": "unexpected error",
67+
"content": {
68+
"application/json": {
69+
"schema": {
70+
"$ref": "#/components/schemas/Error"
71+
}
72+
}
73+
}
74+
}
75+
}
76+
},
77+
"post": {
78+
"summary": "Create a pet",
79+
"operationId": "createPets",
80+
"tags": [
81+
"pets"
82+
],
83+
"responses": {
84+
"201": {
85+
"description": "Null response"
86+
},
87+
"default": {
88+
"description": "unexpected error",
89+
"content": {
90+
"application/json": {
91+
"schema": {
92+
"$ref": "#/components/schemas/Error"
93+
}
94+
}
95+
}
96+
}
97+
}
98+
}
99+
},
100+
"/pets/{petId}": {
101+
"get": {
102+
"summary": "Info for a specific pet",
103+
"operationId": "showPetById",
104+
"tags": [
105+
"pets"
106+
],
107+
"parameters": [
108+
{
109+
"name": "petId",
110+
"in": "path",
111+
"required": true,
112+
"description": "The id of the pet to retrieve",
113+
"schema": {
114+
"type": "string"
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+
}
186+
}

0 commit comments

Comments
 (0)