@@ -231,6 +231,65 @@ public void testDeserializeExampleFlag() {
231
231
assertNull (openAPI .getComponents ().getSchemas ().get ("TestNumberMissing" ).getExample ());
232
232
}
233
233
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
+ assertNotNull (openAPI .getPaths ().get ("/object-with-null-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("foo" ).getValue ());
258
+ assertTrue (openAPI .getPaths ().get ("/object-with-null-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("foo" ).getValueSetFlag ());
259
+ assertNull (openAPI .getPaths ().get ("/object-with-null-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("bar" ).getValue ());
260
+ assertTrue (openAPI .getPaths ().get ("/object-with-null-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("bar" ).getValueSetFlag ());
261
+
262
+ assertNotNull (openAPI .getPaths ().get ("/object-with-null-in-schema-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("a" ).getValue ());
263
+ assertTrue (openAPI .getPaths ().get ("/object-with-null-in-schema-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("a" ).getValueSetFlag ());
264
+ assertNotNull (openAPI .getPaths ().get ("/object-with-null-in-schema-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("b" ).getValue ());
265
+ assertTrue (openAPI .getPaths ().get ("/object-with-null-in-schema-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("b" ).getValueSetFlag ());
266
+ assertNotNull (openAPI .getPaths ().get ("/object-with-null-in-schema-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("c" ).getValue ());
267
+ assertTrue (openAPI .getPaths ().get ("/object-with-null-in-schema-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("c" ).getValueSetFlag ());
268
+ assertNull (openAPI .getPaths ().get ("/object-with-null-in-schema-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("d" ).getValue ());
269
+ assertTrue (openAPI .getPaths ().get ("/object-with-null-in-schema-example" ).getGet ().getResponses ().get ("200" ).getContent ().get ("application/json" ).getExamples ().get ("d" ).getValueSetFlag ());
270
+
271
+
272
+ assertNull (openAPI .getComponents ().getSchemas ().get ("ObjectWithNullExample" ).getExample ());
273
+ assertTrue (openAPI .getComponents ().getSchemas ().get ("ObjectWithNullExample" ).getExampleSetFlag ());
274
+
275
+ assertNotNull (openAPI .getComponents ().getSchemas ().get ("ObjectWithNullInSchemaExample" ).getExample ());
276
+ assertTrue (openAPI .getComponents ().getSchemas ().get ("ObjectWithNullInSchemaExample" ).getExampleSetFlag ());
277
+
278
+ assertNotNull (((Schema )openAPI .getComponents ().getSchemas ().get ("ObjectWithNullPropertyExample" ).getProperties ().get ("a" )).getExample ());
279
+ assertTrue (((Schema )openAPI .getComponents ().getSchemas ().get ("ObjectWithNullPropertyExample" ).getProperties ().get ("a" )).getExampleSetFlag ());
280
+ assertNull (((Schema )openAPI .getComponents ().getSchemas ().get ("ObjectWithNullPropertyExample" ).getProperties ().get ("b" )).getExample ());
281
+ assertTrue (((Schema )openAPI .getComponents ().getSchemas ().get ("ObjectWithNullPropertyExample" ).getProperties ().get ("b" )).getExampleSetFlag ());
282
+
283
+ assertNull (openAPI .getComponents ().getSchemas ().get ("StringWithNullExample" ).getExample ());
284
+ assertTrue (openAPI .getComponents ().getSchemas ().get ("StringWithNullExample" ).getExampleSetFlag ());
285
+
286
+ assertNull (openAPI .getComponents ().getSchemas ().get ("ArrayWithNullArrayExample" ).getExample ());
287
+ assertTrue (openAPI .getComponents ().getSchemas ().get ("ArrayWithNullArrayExample" ).getExampleSetFlag ());
288
+
289
+ assertNull (((ArraySchema )openAPI .getComponents ().getSchemas ().get ("ArrayWithNullItemExample" )).getItems ().getExample ());
290
+ assertTrue (((ArraySchema )openAPI .getComponents ().getSchemas ().get ("ArrayWithNullItemExample" )).getItems ().getExampleSetFlag ());
291
+ }
292
+
234
293
@ Test
235
294
public void testIssueFlattenAdditionalPropertiesSchemaInlineModelTrue () {
236
295
OpenAPIV3Parser openApiParser = new OpenAPIV3Parser ();
0 commit comments