Skip to content

Commit 9081c3e

Browse files
committed
Fix for issue 922
Fix for issue 922
1 parent d4270bc commit 9081c3e

File tree

3 files changed

+198
-4
lines changed

3 files changed

+198
-4
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,10 +2152,12 @@ public Schema getSchema(ObjectNode node, String location, ParseResult result){
21522152
}
21532153

21542154
value = getString("default", node, false, location, result);
2155+
schema.setDefault(false);
21552156
if (StringUtils.isNotBlank(value)) {
21562157
schema.setDefault(value);
21572158
}
21582159

2160+
21592161
//discriminator
21602162

21612163
bool = getBoolean("nullable", node, false, location, result);

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44

5+
import com.sun.org.apache.xpath.internal.operations.Bool;
56
import io.swagger.v3.oas.models.Components;
67
import io.swagger.v3.oas.models.OpenAPI;
78
import io.swagger.v3.oas.models.media.ArraySchema;
@@ -21,10 +22,7 @@
2122

2223
import java.util.List;
2324

24-
25-
import static org.testng.Assert.assertEquals;
26-
import static org.testng.Assert.assertNotNull;
27-
import static org.testng.Assert.assertTrue;
25+
import static org.testng.Assert.*;
2826

2927
public class OpenAPIParserTest {
3028
@Test
@@ -460,4 +458,15 @@ public void testIssue879() {
460458
.get$ref();
461459
assertEquals(ref, "#/components/callbacks/callbackEvent");
462460
}
461+
462+
@Test
463+
public void testSample() {
464+
OpenAPIParser openAPIParser = new OpenAPIParser();
465+
ParseOptions options = new ParseOptions();
466+
OpenAPI openAPI = openAPIParser.readLocation("petstore.json",null,null).getOpenAPI();
467+
assertNotNull(openAPI);
468+
assertEquals(openAPI.getComponents().getSchemas().get("Pet").getDefault(),Boolean.FALSE);
469+
470+
}
471+
463472
}
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{
2+
"openapi": "3.0.0",
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+
"paths": {
16+
"/pets": {
17+
"get": {
18+
"summary": "List all pets",
19+
"operationId": "listPets",
20+
"tags": [
21+
"pets"
22+
],
23+
"parameters": [
24+
{
25+
"name": "limit",
26+
"in": "query",
27+
"description": "How many items to return at one time (max 100)",
28+
"required": false,
29+
"schema": {
30+
"type": "integer",
31+
"format": "int32"
32+
}
33+
}
34+
],
35+
"responses": {
36+
"200": {
37+
"description": "A paged array of pets",
38+
"headers": {
39+
"x-next": {
40+
"description": "A link to the next page of responses",
41+
"schema": {
42+
"type": "string"
43+
}
44+
}
45+
},
46+
"content": {
47+
"application/json": {
48+
"schema": {
49+
"$ref": "#/components/schemas/Pets"
50+
}
51+
}
52+
}
53+
},
54+
"default": {
55+
"description": "unexpected error",
56+
"content": {
57+
"application/json": {
58+
"schema": {
59+
"$ref": "#/components/schemas/Error"
60+
}
61+
}
62+
}
63+
}
64+
}
65+
},
66+
"post": {
67+
"summary": "Create a pet",
68+
"operationId": "createPets",
69+
"tags": [
70+
"pets"
71+
],
72+
"responses": {
73+
"201": {
74+
"description": "Null response"
75+
},
76+
"default": {
77+
"description": "unexpected error",
78+
"content": {
79+
"application/json": {
80+
"schema": {
81+
"$ref": "#/components/schemas/Error"
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}
88+
},
89+
"/pets/{petId}": {
90+
"get": {
91+
"summary": "Info for a specific pet",
92+
"operationId": "showPetById",
93+
"tags": [
94+
"pets"
95+
],
96+
"parameters": [
97+
{
98+
"name": "petId",
99+
"in": "path",
100+
"required": true,
101+
"description": "The id of the pet to retrieve",
102+
"schema": {
103+
"type": "string"
104+
}
105+
},
106+
{
107+
"name": "test",
108+
"in": "query",
109+
"description": "The id of the pet to retrieve",
110+
"schema": {
111+
"type": "string"
112+
}
113+
}
114+
],
115+
"responses": {
116+
"200": {
117+
"description": "Expected response to a valid request",
118+
"content": {
119+
"application/json": {
120+
"schema": {
121+
"$ref": "#/components/schemas/Pets"
122+
}
123+
}
124+
}
125+
},
126+
"default": {
127+
"description": "unexpected error",
128+
"content": {
129+
"application/json": {
130+
"schema": {
131+
"$ref": "#/components/schemas/Error"
132+
}
133+
}
134+
}
135+
}
136+
}
137+
}
138+
}
139+
},
140+
"components": {
141+
"schemas": {
142+
"Pet": {
143+
"required": [
144+
"id",
145+
"name"
146+
],
147+
"properties": {
148+
"id": {
149+
"type": "integer",
150+
"format": "int64"
151+
},
152+
"name": {
153+
"type": "string"
154+
},
155+
"tag": {
156+
"type": "string"
157+
}
158+
}
159+
},
160+
"Pets": {
161+
"type": "array",
162+
"items": {
163+
"$ref": "#/components/schemas/Pet"
164+
}
165+
},
166+
"Error": {
167+
"required": [
168+
"code",
169+
"message"
170+
],
171+
"properties": {
172+
"code": {
173+
"type": "integer",
174+
"format": "int32"
175+
},
176+
"message": {
177+
"type": "string"
178+
}
179+
}
180+
}
181+
}
182+
}
183+
}

0 commit comments

Comments
 (0)