@@ -96,7 +96,6 @@ public void flatten(OpenAPI openAPI) {
96
96
} else if (model instanceof ArraySchema ) {
97
97
ArraySchema am = (ArraySchema ) model ;
98
98
Schema inner = am .getItems ();
99
-
100
99
if (isObjectSchema (inner )) {
101
100
if (inner .getProperties () != null && inner .getProperties ().size () > 0 ) {
102
101
flattenProperties (inner .getProperties (), pathname );
@@ -186,7 +185,7 @@ public void flatten(OpenAPI openAPI) {
186
185
if (media .getSchema () != null ) {
187
186
Schema mediaSchema = media .getSchema ();
188
187
if (isObjectSchema (mediaSchema )) {
189
- if (mediaSchema .getProperties () != null && mediaSchema .getProperties ().size () > 0 ) {
188
+ if (mediaSchema .getProperties () != null && mediaSchema .getProperties ().size () > 0 || mediaSchema instanceof ComposedSchema ) {
190
189
String modelName = resolveModelName (mediaSchema .getTitle (), "inline_response_" + key );
191
190
String existing = matchGenerated (mediaSchema );
192
191
if (existing != null ) {
@@ -196,63 +195,31 @@ public void flatten(OpenAPI openAPI) {
196
195
addGenerated (modelName , mediaSchema );
197
196
openAPI .getComponents ().addSchemas (modelName , mediaSchema );
198
197
}
199
- }else if (mediaSchema instanceof ComposedSchema ) {
200
- String modelName = resolveModelName (mediaSchema .getTitle (), "inline_response_" + key );
201
- String existing = matchGenerated (mediaSchema );
202
- if (existing != null ) {
203
- media .setSchema (this .makeRefProperty (existing , mediaSchema ));
204
- } else {
205
- media .setSchema (this .makeRefProperty (modelName , mediaSchema ));
206
- addGenerated (modelName , mediaSchema );
207
- openAPI .getComponents ().addSchemas (modelName , mediaSchema );
198
+ }else if (mediaSchema .getAdditionalProperties () != null && !(mediaSchema .getAdditionalProperties () instanceof Boolean )) {
199
+ Schema innerProperty = (Schema ) mediaSchema .getAdditionalProperties ();
200
+ if (isObjectSchema (innerProperty )) {
201
+ key = "inline_response_map" + key ;
202
+ flattenMapSchema (innerProperty , key , pathname , mediaSchema );
203
+ } else if (innerProperty instanceof ArraySchema ) {
204
+ ArraySchema arraySchema = (ArraySchema ) innerProperty ;
205
+ Schema inner = arraySchema .getItems ();
206
+ if (isObjectSchema (inner )) {
207
+ key = "inline_response_map_items" + key ;
208
+ flattenMapSchema (inner ,key ,pathname ,mediaSchema );
209
+ }
208
210
}
209
211
}
210
-
211
212
}else if (mediaSchema instanceof ArraySchema ) {
212
213
ArraySchema ap = (ArraySchema ) mediaSchema ;
213
214
Schema inner = ap .getItems ();
214
-
215
215
if (isObjectSchema (inner )) {
216
- if (inner .getProperties () != null && inner .getProperties ().size () > 0 ) {
217
- flattenProperties (inner .getProperties (), pathname );
218
- String modelName = resolveModelName (inner .getTitle (),
219
- "inline_response_" + key );
220
- String existing = matchGenerated (inner );
221
- if (existing != null ) {
222
- ap .setItems (this .makeRefProperty (existing , inner ));
223
- } else {
224
- ap .setItems (this .makeRefProperty (modelName , inner ));
225
- addGenerated (modelName , inner );
226
- openAPI .getComponents ().addSchemas (modelName , inner );
227
- }
228
- }else if (inner instanceof ComposedSchema && this .flattenComposedSchemas ){
229
- flattenComposedSchema (inner ,key );
230
- if (inner .get$ref () == null ) {
231
- String modelName = resolveModelName (inner .getTitle (), "inline_response_items" + key );
232
- ap .setItems (this .makeRefProperty (modelName , inner ));
233
- addGenerated (modelName , inner );
234
- openAPI .getComponents ().addSchemas (modelName , inner );
235
- }
236
- }
216
+ flattenArraySchema (inner , key , pathname , ap );
237
217
}
238
-
239
- } else if (mediaSchema .getAdditionalProperties () != null && mediaSchema .getAdditionalProperties () instanceof Schema ) {
240
-
218
+ } else if (mediaSchema .getAdditionalProperties () != null && !(mediaSchema .getAdditionalProperties () instanceof Boolean )) {
241
219
Schema innerProperty = (Schema ) mediaSchema .getAdditionalProperties ();
242
220
if (isObjectSchema (innerProperty )) {
243
- if (innerProperty .getProperties () != null && innerProperty .getProperties ().size () > 0 ) {
244
- flattenProperties (innerProperty .getProperties (), pathname );
245
- String modelName = resolveModelName (innerProperty .getTitle (),
246
- "inline_response_" + key );
247
- String existing = matchGenerated (innerProperty );
248
- if (existing != null ) {
249
- mediaSchema .setAdditionalProperties (new Schema ().$ref (existing ));
250
- } else {
251
- mediaSchema .setAdditionalProperties (new Schema ().$ref (modelName ));
252
- addGenerated (modelName , innerProperty );
253
- openAPI .getComponents ().addSchemas (modelName , innerProperty );
254
- }
255
- }
221
+ key = "inline_response_map" + key ;
222
+ flattenMapSchema (innerProperty , key , pathname , mediaSchema );
256
223
}
257
224
}
258
225
}
@@ -301,7 +268,6 @@ public void flatten(OpenAPI openAPI) {
301
268
} else if (model instanceof ComposedSchema ) {
302
269
ComposedSchema composedSchema = (ComposedSchema ) model ;
303
270
String inlineModelName = "" ;
304
-
305
271
List <Schema > list = null ;
306
272
if (composedSchema .getAllOf () != null ) {
307
273
list = composedSchema .getAllOf ();
@@ -334,6 +300,54 @@ public void flatten(OpenAPI openAPI) {
334
300
}
335
301
}
336
302
303
+ private void flattenArraySchema (Schema inner , String key , String pathname , ArraySchema ap ) {
304
+ if (inner .getProperties () != null && inner .getProperties ().size () > 0 ) {
305
+ flattenProperties (inner .getProperties (), pathname );
306
+ key = "inline_response_" + key ;
307
+ String modelName = resolveModelName (inner .getTitle (), key );
308
+ String existing = matchGenerated (inner );
309
+ if (existing != null ) {
310
+ ap .setItems (this .makeRefProperty (existing , inner ));
311
+ } else {
312
+ ap .setItems (this .makeRefProperty (modelName , inner ));
313
+ addGenerated (modelName , inner );
314
+ openAPI .getComponents ().addSchemas (modelName , inner );
315
+ }
316
+ }else if (inner instanceof ComposedSchema && this .flattenComposedSchemas ){
317
+ flattenComposedSchema (inner ,key );
318
+ if (inner .get$ref () == null ) {
319
+ key = "inline_response_items" + key ;
320
+ String modelName = resolveModelName (inner .getTitle (), key );
321
+ ap .setItems (this .makeRefProperty (modelName , inner ));
322
+ addGenerated (modelName , inner );
323
+ openAPI .getComponents ().addSchemas (modelName , inner );
324
+ }
325
+ }
326
+ }
327
+
328
+
329
+ private void flattenMapSchema (Schema innerProperty , String key , String pathname , Schema mediaSchema ) {
330
+ if (innerProperty .getProperties () != null && innerProperty .getProperties ().size () > 0 ) {
331
+ flattenProperties (innerProperty .getProperties (), pathname );
332
+ String modelName = resolveModelName (innerProperty .getTitle (), key );
333
+ String existing = matchGenerated (innerProperty );
334
+ if (existing != null ) {
335
+ mediaSchema .setAdditionalProperties (new Schema ().$ref (existing ));
336
+ } else {
337
+ mediaSchema .setAdditionalProperties (new Schema ().$ref (modelName ));
338
+ addGenerated (modelName , innerProperty );
339
+ openAPI .getComponents ().addSchemas (modelName , innerProperty );
340
+ }
341
+ }else if (innerProperty instanceof ComposedSchema && this .flattenComposedSchemas ){
342
+ flattenComposedSchema (innerProperty ,key );
343
+ if (innerProperty .get$ref () == null ) {
344
+ String modelName = resolveModelName (innerProperty .getTitle (), key );
345
+ mediaSchema .setAdditionalProperties (new Schema ().$ref (modelName ));
346
+ addGenerated (modelName , innerProperty );
347
+ openAPI .getComponents ().addSchemas (modelName , innerProperty );
348
+ }
349
+ }
350
+ }
337
351
338
352
339
353
/**
@@ -418,12 +432,9 @@ public void flattenProperties(Map<String, Schema> properties, String path) {
418
432
for (String key : properties .keySet ()) {
419
433
Schema property = properties .get (key );
420
434
if (isObjectSchema (property ) && property .getProperties () != null && property .getProperties ().size () > 0 ) {
421
-
422
435
String modelName = resolveModelName (property .getTitle (), path + "_" + key );
423
436
Schema model = createModelFromProperty (property , modelName );
424
-
425
437
String existing = matchGenerated (model );
426
-
427
438
if (existing != null ) {
428
439
propsToUpdate .put (key , new Schema ().$ref (existing ));
429
440
} else {
@@ -435,7 +446,6 @@ public void flattenProperties(Map<String, Schema> properties, String path) {
435
446
} else if (property instanceof ArraySchema ) {
436
447
ArraySchema ap = (ArraySchema ) property ;
437
448
Schema inner = ap .getItems ();
438
-
439
449
if (isObjectSchema (inner )) {
440
450
if (inner .getProperties () != null && inner .getProperties ().size () > 0 ) {
441
451
flattenProperties (inner .getProperties (), path );
@@ -449,23 +459,9 @@ public void flattenProperties(Map<String, Schema> properties, String path) {
449
459
addGenerated (modelName , innerModel );
450
460
openAPI .getComponents ().addSchemas (modelName , innerModel );
451
461
}
452
- }else if (inner instanceof ComposedSchema && this .flattenComposedSchemas ){
453
- ComposedSchema composedSchema = ( ComposedSchema ) inner ;
462
+ }else if (inner instanceof ComposedSchema && this .flattenComposedSchemas ) {
463
+ flattenComposedSchema ( inner , key ) ;
454
464
String modelName = resolveModelName (inner .getTitle (), path + "_" + key );
455
- List <Schema > list = null ;
456
- if (composedSchema .getAllOf () != null ) {
457
- list = composedSchema .getAllOf ();
458
- }else if (composedSchema .getAnyOf () != null ) {
459
- list = composedSchema .getAnyOf ();
460
- }else if (composedSchema .getOneOf () != null ) {
461
- list = composedSchema .getOneOf ();
462
- }
463
- for (int i = 0 ; i <list .size ();i ++){
464
- if (list .get (i ).getProperties ()!= null ){
465
- flattenProperties (list .get (i ).getProperties (), modelName );
466
- }
467
- }
468
-
469
465
Schema innerModel = createModelFromProperty (inner , modelName );
470
466
String existing = matchGenerated (innerModel );
471
467
if (existing != null ) {
@@ -476,11 +472,9 @@ public void flattenProperties(Map<String, Schema> properties, String path) {
476
472
openAPI .getComponents ().addSchemas (modelName , innerModel );
477
473
}
478
474
}
479
-
480
475
}
481
- } else if (property .getAdditionalProperties () != null && property .getAdditionalProperties () instanceof Schema ) {
476
+ } else if (property .getAdditionalProperties () != null && !( property .getAdditionalProperties () instanceof Boolean ) ) {
482
477
Schema inner = (Schema ) property .getAdditionalProperties ();
483
-
484
478
if (isObjectSchema (inner )) {
485
479
if (inner .getProperties () != null && inner .getProperties ().size () > 0 ) {
486
480
flattenProperties (inner .getProperties (), path );
@@ -623,11 +617,9 @@ public Schema modelFromProperty(Schema object, @SuppressWarnings("unused") Strin
623
617
ArraySchema model = new ArraySchema ();
624
618
model .setDescription (description );
625
619
model .setExample (example );
626
- if (object .getAdditionalProperties () != null && object .getAdditionalProperties () instanceof Schema ) {
620
+ if (object .getAdditionalProperties () != null && !( object .getAdditionalProperties () instanceof Boolean ) ) {
627
621
model .setItems ((Schema ) object .getAdditionalProperties ());
628
622
}
629
-
630
-
631
623
return model ;
632
624
}
633
625
0 commit comments