@@ -83,6 +83,101 @@ public class OpenAPIV3ParserTest {
83
83
protected WireMockServer wireMockServer ;
84
84
85
85
86
+ @ Test
87
+ public void testIssue1367 () {
88
+ OpenAPIV3Parser openApiParser = new OpenAPIV3Parser ();
89
+ ParseOptions options = new ParseOptions ();
90
+ options .setResolve (true );
91
+ options .setResolveCombinators (true );
92
+ options .setResolveFully (true );
93
+ options .setFlatten (true );
94
+ SwaggerParseResult parseResult = openApiParser .readLocation ("issue-1367.yaml" , null , options );
95
+ OpenAPI openAPI = parseResult .getOpenAPI ();
96
+ assertTrue (((Schema )openAPI .getComponents ().getSchemas ().get ("TestDTO" ).getProperties ().get ("choice" )).getEnum () != null );
97
+ }
98
+
99
+ @ Test
100
+ public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue () {
101
+ OpenAPIV3Parser openApiParser = new OpenAPIV3Parser ();
102
+ ParseOptions options = new ParseOptions ();
103
+ options .setResolve (true );
104
+ options .setFlatten (true );
105
+ options .setFlattenComposedSchemas (true );
106
+ options .setCamelCaseFlattenNaming (true );
107
+ SwaggerParseResult parseResult = openApiParser .readLocation ("additionalPropertiesFlatten.yaml" , null , options );
108
+ OpenAPI openAPI = parseResult .getOpenAPI ();
109
+
110
+ //responses
111
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("Inline_response_map200" ));
112
+ assertEquals (((ComposedSchema )openAPI .getComponents ().getSchemas ().get ("Inline_response_map200" )).getOneOf ().get (0 ).get$ref (),"#/components/schemas/Macaw1" );
113
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("Inline_response_map_items404" ));
114
+ assertEquals (((ComposedSchema )openAPI .getComponents ().getSchemas ().get ("Inline_response_map_items404" )).getAnyOf ().get (0 ).get$ref (),"#/components/schemas/Macaw2" );
115
+ }
116
+
117
+
118
+ @ Test
119
+ public void testIssueFlattenArraySchemaItemsInlineModelFalse () {
120
+ OpenAPIV3Parser openApiParser = new OpenAPIV3Parser ();
121
+ ParseOptions options = new ParseOptions ();
122
+ options .setResolve (true );
123
+ options .setFlatten (true );
124
+ options .setFlattenComposedSchemas (false );
125
+ options .setCamelCaseFlattenNaming (false );
126
+ SwaggerParseResult parseResult = openApiParser .readLocation ("flattenArrayItems.yaml" , null , options );
127
+ OpenAPI openAPI = parseResult .getOpenAPI ();
128
+
129
+ //responses
130
+ assertNull (openAPI .getComponents ().getSchemas ().get ("Inline_response_items200" ));
131
+ assertNull (openAPI .getComponents ().getSchemas ().get ("Inline_response_400" ));
132
+
133
+ //parameters
134
+ assertNull (openAPI .getComponents ().getSchemas ().get ("Inline_parameter_items_bodylimit" ));
135
+ assertNull (openAPI .getComponents ().getSchemas ().get ("Pagelimit" ));
136
+
137
+ //requestBodies
138
+ assertNull (openAPI .getComponents ().getSchemas ().get ("Body" ));
139
+ assertNull (openAPI .getComponents ().getSchemas ().get ("Inline_response_items200" ));
140
+
141
+ //components
142
+ assertNull (openAPI .getComponents ().getSchemas ().get ("Inline_array_items_ArrayTest" ));
143
+
144
+ }
145
+
146
+ @ Test
147
+ public void testIssueFlattenArraySchemaItemsInlineModelTrue () {
148
+ OpenAPIV3Parser openApiParser = new OpenAPIV3Parser ();
149
+ ParseOptions options = new ParseOptions ();
150
+ options .setResolve (true );
151
+ options .setFlatten (true );
152
+ options .setFlattenComposedSchemas (true );
153
+ options .setCamelCaseFlattenNaming (true );
154
+ SwaggerParseResult parseResult = openApiParser .readLocation ("flattenArrayItems.yaml" , null , options );
155
+ OpenAPI openAPI = parseResult .getOpenAPI ();
156
+
157
+ //responses
158
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("Inline_response_items200" ));
159
+ assertEquals (((ComposedSchema )openAPI .getComponents ().getSchemas ().get ("Inline_response_items200" )).getAnyOf ().get (0 ).get$ref (),"#/components/schemas/Macaw" );
160
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("Inline_response_400" ));
161
+ assertEquals (((ComposedSchema )openAPI .getComponents ().getSchemas ().get ("Inline_response_400" )).getAnyOf ().get (0 ).get$ref (),"#/components/schemas/Macaw3" );
162
+
163
+ //parameters
164
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("Inline_parameter_items_bodylimit" ));
165
+ assertEquals (((ComposedSchema )openAPI .getComponents ().getSchemas ().get ("Inline_parameter_items_bodylimit" )).getAnyOf ().get (0 ).get$ref (),"#/components/schemas/Macaw1" );
166
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("Pagelimit" ));
167
+ assertEquals (((ComposedSchema )openAPI .getComponents ().getSchemas ().get ("Pagelimit" )).getOneOf ().get (0 ).get$ref (),"#/components/schemas/Macaw2" );
168
+
169
+ //requestBodies
170
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("Body" ));
171
+ assertEquals (((ComposedSchema )openAPI .getComponents ().getSchemas ().get ("Body" )).getAllOf ().get (1 ).get$ref (),"#/components/schemas/requestBodiesAllOf_2" );
172
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("Inline_response_items200" ));
173
+ assertEquals (((ComposedSchema )openAPI .getComponents ().getSchemas ().get ("Inline_body_items_applicationxml_requestBodies" )).getAllOf ().get (1 ).get$ref (),"#/components/schemas/ApplicationxmlAllOf_2" );
174
+
175
+ //components
176
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("Inline_array_items_ArrayTest" ));
177
+ assertEquals (((ComposedSchema )openAPI .getComponents ().getSchemas ().get ("Inline_array_items_ArrayTest" )).getOneOf ().get (1 ).get$ref (),"#/components/schemas/ArrayTestOneOf_2" );
178
+ }
179
+
180
+
86
181
@ Test
87
182
public void testCamelCaseFlattenNamingFalse () {
88
183
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser ();
@@ -1924,7 +2019,7 @@ public void readingSpecNodeShouldNotOverQuotingStringExample() throws Exception
1924
2019
String yaml = Files .readFile (new File ("src/test/resources/over-quoted-example.yaml" ));
1925
2020
JsonNode rootNode = Yaml .mapper ().readValue (yaml , JsonNode .class );
1926
2021
OpenAPIV3Parser parser = new OpenAPIV3Parser ();
1927
- OpenAPI openAPI = (parser .readWithInfo (null , rootNode )).getOpenAPI ();
2022
+ OpenAPI openAPI = (parser .parseJsonNode (null , rootNode )).getOpenAPI ();
1928
2023
1929
2024
Map <String , Schema > definitions = openAPI .getComponents ().getSchemas ();
1930
2025
assertEquals ("NoQuotePlease" , definitions .get ("CustomerType" ).getExample ());
@@ -2326,6 +2421,26 @@ public void testIssue1335() {
2326
2421
assertNotNull (result .getOpenAPI ().getComponents ().getExamples ().get ("ex1" ));
2327
2422
}
2328
2423
2424
+ @ Test
2425
+ public void testEmptyQueryParameterExample () {
2426
+ final ParseOptions options = new ParseOptions ();
2427
+ options .setResolve (true );
2428
+
2429
+ SwaggerParseResult result = new OpenAPIV3Parser ()
2430
+ .readLocation ("src/test/resources/emptyQueryParameter.yaml" , null , options );
2431
+ assertEquals ("" , result .getOpenAPI ().getPaths ().get ("/foo" ).getGet ().getParameters ().get (0 ).getExample ());
2432
+ }
2433
+
2434
+ @ Test
2435
+ public void testBlankQueryParameterExample () {
2436
+ final ParseOptions options = new ParseOptions ();
2437
+ options .setResolve (true );
2438
+
2439
+ SwaggerParseResult result = new OpenAPIV3Parser ()
2440
+ .readLocation ("src/test/resources/blankQueryParameter.yaml" , null , options );
2441
+ assertEquals (" " , result .getOpenAPI ().getPaths ().get ("/foo" ).getGet ().getParameters ().get (0 ).getExample ());
2442
+ }
2443
+
2329
2444
@ Test
2330
2445
public void testRegressionIssue1236 () {
2331
2446
final ParseOptions options = new ParseOptions ();
0 commit comments