@@ -86,10 +86,13 @@ public void flatten(OpenAPI openAPI) {
86
86
addGenerated (modelName , model );
87
87
openAPI .getComponents ().addSchemas (modelName , model );
88
88
} else if (model instanceof ComposedSchema ) {
89
- String modelName = resolveModelName (model .getTitle (), "body" );
90
- mediaType .setSchema (new Schema ().$ref (modelName ));
91
- addGenerated (modelName , model );
92
- openAPI .getComponents ().addSchemas (modelName , model );
89
+ flattenComposedSchema (model , pathname );
90
+ if (model .get$ref () == null ) {
91
+ String modelName = resolveModelName (model .getTitle (), "body" );
92
+ mediaType .setSchema (this .makeRefProperty (modelName , model ));
93
+ addGenerated (modelName , model );
94
+ openAPI .getComponents ().addSchemas (modelName , model );
95
+ }
93
96
} else if (model instanceof ArraySchema ) {
94
97
ArraySchema am = (ArraySchema ) model ;
95
98
Schema inner = am .getItems ();
@@ -106,6 +109,14 @@ public void flatten(OpenAPI openAPI) {
106
109
addGenerated (modelName , inner );
107
110
openAPI .getComponents ().addSchemas (modelName , inner );
108
111
}
112
+ }else if (inner instanceof ComposedSchema && this .flattenComposedSchemas ){
113
+ flattenComposedSchema (inner ,key );
114
+ if (inner .get$ref () == null ) {
115
+ String modelName = resolveModelName (inner .getTitle (), "inline_body_items_" + key + "_" + pathname );
116
+ am .setItems (this .makeRefProperty (modelName , inner ));
117
+ addGenerated (modelName , inner );
118
+ openAPI .getComponents ().addSchemas (modelName , inner );
119
+ }
109
120
}
110
121
}
111
122
}
@@ -149,6 +160,14 @@ public void flatten(OpenAPI openAPI) {
149
160
addGenerated (modelName , am );
150
161
openAPI .getComponents ().addSchemas (modelName , am );
151
162
}
163
+ }else if (inner instanceof ComposedSchema && this .flattenComposedSchemas ){
164
+ flattenComposedSchema (inner , parameter .getName ());
165
+ if (inner .get$ref () == null ) {
166
+ String modelName = resolveModelName (inner .getTitle (), "inline_parameter_items_" + parameter .getName ());
167
+ am .setItems (this .makeRefProperty (modelName , inner ));
168
+ addGenerated (modelName , inner );
169
+ openAPI .getComponents ().addSchemas (modelName , inner );
170
+ }
152
171
}
153
172
}
154
173
}
@@ -177,16 +196,16 @@ public void flatten(OpenAPI openAPI) {
177
196
addGenerated (modelName , mediaSchema );
178
197
openAPI .getComponents ().addSchemas (modelName , mediaSchema );
179
198
}
180
- }
181
- } else if (mediaSchema instanceof ComposedSchema ){
182
- String modelName = resolveModelName (mediaSchema . getTitle (), "inline_response_" + key );
183
- String existing = matchGenerated ( mediaSchema );
184
- if ( existing != null ) {
185
- media . setSchema ( this . makeRefProperty ( existing , mediaSchema ));
186
- } else {
187
- media . setSchema ( this . makeRefProperty ( modelName , mediaSchema ) );
188
- addGenerated (modelName , mediaSchema );
189
- openAPI . getComponents (). addSchemas ( modelName , mediaSchema );
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 );
208
+ }
190
209
}
191
210
192
211
}else if (mediaSchema instanceof ArraySchema ) {
@@ -206,8 +225,17 @@ public void flatten(OpenAPI openAPI) {
206
225
addGenerated (modelName , inner );
207
226
openAPI .getComponents ().addSchemas (modelName , inner );
208
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
+ }
209
236
}
210
237
}
238
+
211
239
} else if (mediaSchema .getAdditionalProperties () != null && mediaSchema .getAdditionalProperties () instanceof Schema ) {
212
240
213
241
Schema innerProperty = (Schema ) mediaSchema .getAdditionalProperties ();
@@ -260,6 +288,14 @@ public void flatten(OpenAPI openAPI) {
260
288
} else {
261
289
m .setItems (new Schema ().$ref (existing ));
262
290
}
291
+ }else if (inner instanceof ComposedSchema && this .flattenComposedSchemas ){
292
+ flattenComposedSchema (inner ,modelName );
293
+ if (inner .get$ref () == null ) {
294
+ modelName = resolveModelName (inner .getTitle (), "inline_array_items_" + modelName );
295
+ m .setItems (this .makeRefProperty (modelName , inner ));
296
+ addGenerated (modelName , inner );
297
+ openAPI .getComponents ().addSchemas (modelName , inner );
298
+ }
263
299
}
264
300
}
265
301
} else if (model instanceof ComposedSchema ) {
@@ -473,6 +509,40 @@ public void flattenProperties(Map<String, Schema> properties, String path) {
473
509
}
474
510
}
475
511
512
+ private void flattenComposedSchema (Schema inner , String key ) {
513
+
514
+ ComposedSchema composedSchema = (ComposedSchema ) inner ;
515
+ String inlineModelName = "" ;
516
+
517
+ List <Schema > list = null ;
518
+ if (composedSchema .getAllOf () != null ) {
519
+ list = composedSchema .getAllOf ();
520
+ inlineModelName = "AllOf" ;
521
+ }else if (composedSchema .getAnyOf () != null ) {
522
+ list = composedSchema .getAnyOf ();
523
+ inlineModelName = "AnyOf" ;
524
+ }else if (composedSchema .getOneOf () != null ) {
525
+ list = composedSchema .getOneOf ();
526
+ inlineModelName = "OneOf" ;
527
+ }
528
+
529
+ for (int i = 0 ; i <list .size ();i ++){
530
+ if (list .get (i ).get$ref () == null ){
531
+ Schema inline = list .get (i );
532
+ if (inline .getProperties ()!= null ){
533
+ flattenProperties (inline .getProperties (), key );
534
+ }
535
+ if (this .flattenComposedSchemas ) {
536
+ int position = i +1 ;
537
+ inlineModelName = resolveModelName (inline .getTitle (), key + inlineModelName + "_" + position );
538
+ list .set (i ,new Schema ().$ref (inlineModelName ));
539
+ addGenerated (inlineModelName , inline );
540
+ openAPI .getComponents ().addSchemas (inlineModelName , inline );
541
+ }
542
+ }
543
+ }
544
+ }
545
+
476
546
@ SuppressWarnings ("static-method" )
477
547
public Schema modelFromProperty (ArraySchema object , @ SuppressWarnings ("unused" ) String path ) {
478
548
String description = object .getDescription ();
@@ -593,7 +663,8 @@ public void copyVendorExtensions(Schema source, Schema target) {
593
663
private boolean isObjectSchema (Schema schema ) {
594
664
return schema instanceof ObjectSchema
595
665
|| "object" .equalsIgnoreCase (schema .getType ())
596
- || (schema .getType () == null && schema .getProperties () != null && !schema .getProperties ().isEmpty ());
666
+ || (schema .getType () == null && schema .getProperties () != null && !schema .getProperties ().isEmpty ()
667
+ || schema instanceof ComposedSchema );
597
668
}
598
669
599
670
public boolean isSkipMatches () {
0 commit comments