Skip to content

Commit dd97788

Browse files
committed
bump core version and add test for null example serialization
1 parent fc0283f commit dd97788

File tree

6 files changed

+734
-5
lines changed

6 files changed

+734
-5
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# http://editorconfig.org
2+
3+
# A special property that should be specified at the top of the file outside of
4+
# any sections. Set to true to stop .editor config file search on current file
5+
root = true
6+
7+
[*]
8+
# Indentation style
9+
# Possible values - tab, space
10+
indent_style = space
11+
12+
# File character encoding
13+
# Possible values - latin1, utf-8, utf-16be, utf-16le
14+
charset = utf-8
15+
16+
[modules/swagger-parser-v3/src/test/resources/**/*.json]
17+
trim_trailing_whitespace = false
18+
19+
[modules/swagger-parser-v3/src/test/resources/**/*.yaml]
20+
trim_trailing_whitespace = false

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public void testIssue251() throws IOException {
232232
assertTrue(parseResult.getOpenAPI().getComponents().getSchemas().size() == 2);
233233
assertTrue(parseResult.getOpenAPI().getPaths().get("/parse").getGet().getParameters().get(0).getSchema().get$ref().equals("#/components/schemas/Parse"));
234234
}
235-
235+
236236
@Test
237237
public void testCantReadDeepProperties() {
238238
OpenAPIV3Parser parser = new OpenAPIV3Parser();
@@ -244,7 +244,7 @@ public void testCantReadDeepProperties() {
244244
Schema projects = (Schema) parseResult.getOpenAPI().getComponents().getSchemas().get("Project").getProperties().get("project_type");
245245
assertEquals(projects.getType(), "integer");
246246
}
247-
247+
248248
@Test
249249
public void testIssueSameRefsDifferentModel() throws IOException {
250250
String pathFile = FileUtils.readFileToString(new File("src/test/resources/same-refs-different-model-domain.yaml"), "UTF-8");
@@ -2966,4 +2966,16 @@ public void testIssue1540() throws Exception{
29662966
Assert.assertNotNull(testPutExtensions.get("x-order"));
29672967
Assert.assertEquals((String)testPutExtensions.get("x-order"),"2147483647");
29682968
}
2969+
2970+
@Test
2971+
public void testNullExample() throws Exception{
2972+
String yamlString = FileUtils.readFileToString(new File("src/test/resources/null-full-example.yaml"), "UTF-8");
2973+
String yamlStringResolved = FileUtils.readFileToString(new File("src/test/resources/null-full-example-resolved.yaml"), "UTF-8");
2974+
ParseOptions options = new ParseOptions();
2975+
options.setResolveFully(true);
2976+
options.setResolveCombinators(false);
2977+
OpenAPI openAPI = new OpenAPIV3Parser().readContents(yamlString, null, options).getOpenAPI();
2978+
Assert.assertNotNull(openAPI);
2979+
assertEquals(Yaml.pretty(openAPI), yamlStringResolved);
2980+
}
29692981
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
openapi: 3.0.2
2+
info:
3+
title: VirtServer support for null examples
4+
version: 1.0.0
5+
paths:
6+
7+
/object-with-null-example:
8+
get:
9+
description: Response should be `null`
10+
responses:
11+
'200':
12+
description: Should be `null`
13+
content:
14+
application/json:
15+
schema:
16+
$ref: '#/components/schemas/ObjectWithNullExample'
17+
18+
/object-with-null-in-schema-example:
19+
get:
20+
description: 'Response should be `{..., "d": null}`'
21+
responses:
22+
'200':
23+
description: 'Should be `{..., "d": null}`'
24+
content:
25+
application/json:
26+
schema:
27+
$ref: '#/components/schemas/ObjectWithNullInSchemaExample'
28+
29+
/object-with-null-property-example:
30+
get:
31+
description: 'Response should be `{"a": 5, "b": null}`'
32+
responses:
33+
'200':
34+
description: 'Should be `{"a": 5, "b": null}`'
35+
content:
36+
application/json:
37+
schema:
38+
$ref: '#/components/schemas/ObjectWithNullPropertyExample'
39+
40+
/string-with-null-example:
41+
get:
42+
description: Response should be `null`
43+
responses:
44+
'200':
45+
description: Should be `null`
46+
content:
47+
application/json:
48+
schema:
49+
$ref: '#/components/schemas/StringWithNullExample'
50+
51+
/array-with-null-array-example:
52+
get:
53+
description: Response should be `null`
54+
responses:
55+
'200':
56+
description: Should be `null`
57+
content:
58+
application/json:
59+
schema:
60+
$ref: '#/components/schemas/ArrayWithNullArrayExample'
61+
62+
/array-with-null-item-example:
63+
get:
64+
description: Response should be `[null]`
65+
responses:
66+
'200':
67+
description: Should be `[null]`
68+
content:
69+
application/json:
70+
schema:
71+
$ref: '#/components/schemas/ArrayWithNullItemExample'
72+
73+
/arrey-with-null-in-array-example:
74+
get:
75+
description: Response should be `["foo", null]`
76+
responses:
77+
'200':
78+
description: Should be `["foo", null]`
79+
content:
80+
application/json:
81+
schema:
82+
$ref: '#/components/schemas/ArrayWithNullInArrayExample'
83+
84+
components:
85+
schemas:
86+
87+
ObjectWithNullExample:
88+
type: object
89+
properties:
90+
foo:
91+
type: string
92+
nullable: true
93+
example: null
94+
95+
ObjectWithNullInSchemaExample:
96+
type: object
97+
example:
98+
a: 5
99+
b: test
100+
c: true
101+
d: null
102+
103+
ObjectWithNullPropertyExample:
104+
type: object
105+
properties:
106+
a:
107+
type: integer
108+
example: 5
109+
b:
110+
type: string
111+
nullable: true
112+
example: null
113+
114+
StringWithNullExample:
115+
type: string
116+
nullable: true
117+
example: null
118+
119+
ArrayWithNullArrayExample:
120+
type: array
121+
items:
122+
type: string
123+
nullable: true
124+
example: null
125+
126+
ArrayWithNullItemExample:
127+
type: array
128+
items:
129+
type: string
130+
nullable: true
131+
example: null
132+
133+
ArrayWithNullInArrayExample:
134+
type: array
135+
items:
136+
type: string
137+
nullable: true
138+
example: [foo, null]

0 commit comments

Comments
 (0)