Skip to content

Commit fe7353d

Browse files
committed
bump parser version up and added test to verify exampleFlags checks on media-types and schemas.
1 parent 67d2aa7 commit fe7353d

File tree

3 files changed

+243
-1
lines changed

3 files changed

+243
-1
lines changed

modules/swagger-parser-v3/src/test/java/io/swagger/v3/parser/test/OpenAPIV3ParserTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,51 @@ public void testDeserializeExampleFlag() {
231231
assertNull(openAPI.getComponents().getSchemas().get("TestNumberMissing").getExample());
232232
}
233233

234+
@Test
235+
public void testExampleFlag() {
236+
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
237+
ParseOptions options = new ParseOptions();
238+
options.setResolve(true);
239+
options.setResolveCombinators(true);
240+
options.setResolveFully(true);
241+
options.setFlatten(true);
242+
SwaggerParseResult parseResult = openApiParser.readLocation("media-type-null-example.yaml", null, options);
243+
244+
OpenAPI openAPI = parseResult.getOpenAPI();
245+
246+
assertNull(openAPI.getPaths().get("/pets/{petId}").getGet().getResponses().get("200").getContent().get("application/json").getExample());
247+
assertTrue(openAPI.getPaths().get("/pets/{petId}").getGet().getResponses().get("200").getContent().get("application/json").getExampleSetFlag());
248+
249+
assertNull(openAPI.getPaths().get("/pet").getPost().getResponses().get("200").getContent().get("application/json").getExample());
250+
assertFalse(openAPI.getPaths().get("/pet").getPost().getResponses().get("200").getContent().get("application/json").getExampleSetFlag());
251+
252+
assertNotNull(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExample());
253+
assertNotNull(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExample());
254+
255+
assertTrue(openAPI.getPaths().get("/pet").getPost().getRequestBody().getContent().get("application/json").getExampleSetFlag());
256+
257+
258+
assertNull(openAPI.getComponents().getSchemas().get("ObjectWithNullExample").getExample());
259+
assertTrue(openAPI.getComponents().getSchemas().get("ObjectWithNullExample").getExampleSetFlag());
260+
261+
assertNotNull(openAPI.getComponents().getSchemas().get("ObjectWithNullInSchemaExample").getExample());
262+
assertTrue(openAPI.getComponents().getSchemas().get("ObjectWithNullInSchemaExample").getExampleSetFlag());
263+
264+
assertNotNull(((Schema)openAPI.getComponents().getSchemas().get("ObjectWithNullPropertyExample").getProperties().get("a")).getExample());
265+
assertTrue(((Schema)openAPI.getComponents().getSchemas().get("ObjectWithNullPropertyExample").getProperties().get("a")).getExampleSetFlag());
266+
assertNull(((Schema)openAPI.getComponents().getSchemas().get("ObjectWithNullPropertyExample").getProperties().get("b")).getExample());
267+
assertTrue(((Schema)openAPI.getComponents().getSchemas().get("ObjectWithNullPropertyExample").getProperties().get("b")).getExampleSetFlag());
268+
269+
assertNull(openAPI.getComponents().getSchemas().get("StringWithNullExample").getExample());
270+
assertTrue(openAPI.getComponents().getSchemas().get("StringWithNullExample").getExampleSetFlag());
271+
272+
assertNull(openAPI.getComponents().getSchemas().get("ArrayWithNullArrayExample").getExample());
273+
assertTrue(openAPI.getComponents().getSchemas().get("ArrayWithNullArrayExample").getExampleSetFlag());
274+
275+
assertNull(((ArraySchema)openAPI.getComponents().getSchemas().get("ArrayWithNullItemExample")).getItems().getExample());
276+
assertTrue(((ArraySchema)openAPI.getComponents().getSchemas().get("ArrayWithNullItemExample")).getItems().getExampleSetFlag());
277+
}
278+
234279
@Test
235280
public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue() {
236281
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser();
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
openapi: "3.0.1"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: https://petstore3.swagger.io/api/v3
9+
paths:
10+
/pet:
11+
post:
12+
tags:
13+
- pet
14+
summary: Add a new pet to the store
15+
operationId: addPet
16+
requestBody:
17+
description: Pet object that needs to be added to the store
18+
content:
19+
application/json:
20+
schema:
21+
$ref: '#/components/schemas/Pet'
22+
example:
23+
id: 10
24+
name: kitty
25+
tag: something
26+
required: true
27+
responses:
28+
200:
29+
description: Expected response to a valid request
30+
content:
31+
application/json:
32+
schema:
33+
$ref: "#/components/schemas/Pet"
34+
/pets/{petId}:
35+
get:
36+
summary: Info for a specific pet
37+
operationId: showPetById
38+
tags:
39+
- pets
40+
parameters:
41+
- name: petId
42+
in: path
43+
required: true
44+
description: The id of the pet to retrieve
45+
schema:
46+
type: string
47+
responses:
48+
200:
49+
description: Expected response to a valid request
50+
content:
51+
application/json:
52+
schema:
53+
$ref: "#/components/schemas/Pet"
54+
example: null
55+
/object-with-null-example:
56+
get:
57+
description: ''
58+
responses:
59+
'200':
60+
description: ''
61+
content:
62+
application/json:
63+
schema:
64+
$ref: '#/components/schemas/ObjectWithNullExample'
65+
66+
/object-with-null-in-schema-example:
67+
get:
68+
description: ''
69+
responses:
70+
'200':
71+
description: ''
72+
content:
73+
application/json:
74+
schema:
75+
$ref: '#/components/schemas/ObjectWithNullInSchemaExample'
76+
77+
/object-with-null-property-example:
78+
get:
79+
description: ''
80+
responses:
81+
'200':
82+
description: ''
83+
content:
84+
application/json:
85+
schema:
86+
$ref: '#/components/schemas/ObjectWithNullPropertyExample'
87+
88+
/string-with-null-example:
89+
get:
90+
description: ''
91+
responses:
92+
'200':
93+
description: ''
94+
content:
95+
application/json:
96+
schema:
97+
$ref: '#/components/schemas/StringWithNullExample'
98+
99+
/array-with-null-array-example:
100+
get:
101+
description: ''
102+
responses:
103+
'200':
104+
description: ''
105+
content:
106+
application/json:
107+
schema:
108+
$ref: '#/components/schemas/ArrayWithNullArrayExample'
109+
110+
/array-with-null-item-example:
111+
get:
112+
description: ''
113+
responses:
114+
'200':
115+
description: ''
116+
content:
117+
application/json:
118+
schema:
119+
$ref: '#/components/schemas/ArrayWithNullItemExample'
120+
121+
/arrey-with-null-in-array-example:
122+
get:
123+
description: ''
124+
responses:
125+
'200':
126+
description: ''
127+
content:
128+
application/json:
129+
schema:
130+
$ref: '#/components/schemas/ArrayWithNullInArrayExample'
131+
components:
132+
schemas:
133+
Pet:
134+
required:
135+
- id
136+
- name
137+
properties:
138+
id:
139+
type: integer
140+
format: int64
141+
name:
142+
type: string
143+
tag:
144+
type: string
145+
146+
ObjectWithNullExample:
147+
type: object
148+
properties:
149+
foo:
150+
type: string
151+
nullable: true
152+
example: null
153+
154+
ObjectWithNullInSchemaExample:
155+
type: object
156+
example:
157+
a: 5
158+
b: test
159+
c: true
160+
d: null
161+
162+
ObjectWithNullPropertyExample:
163+
type: object
164+
properties:
165+
a:
166+
type: integer
167+
example: 5
168+
b:
169+
type: string
170+
nullable: true
171+
example: null
172+
173+
StringWithNullExample:
174+
type: string
175+
nullable: true
176+
example: null
177+
178+
ArrayWithNullArrayExample:
179+
type: array
180+
items:
181+
type: string
182+
nullable: true
183+
example: null
184+
185+
ArrayWithNullItemExample:
186+
type: array
187+
items:
188+
type: string
189+
nullable: true
190+
example: null
191+
192+
ArrayWithNullInArrayExample:
193+
type: array
194+
items:
195+
type: string
196+
nullable: true
197+
example: [foo, null]

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@
369369
<swagger-parser-v2-version>1.0.55</swagger-parser-v2-version>
370370
<commons-io-version>2.6</commons-io-version>
371371
<slf4j-version>1.7.30</slf4j-version>
372-
<swagger-core-version>2.1.7</swagger-core-version>
372+
<swagger-core-version>2.1.10-SNAPSHOT</swagger-core-version>
373373
<swagger-core-v2-version>1.6.2</swagger-core-v2-version>
374374
<junit-version>4.13.1</junit-version>
375375
<testng-version>6.14.2</testng-version>

0 commit comments

Comments
 (0)