9
9
import io .swagger .codegen .v3 .CodegenProperty ;
10
10
import io .swagger .codegen .v3 .ISchemaHandler ;
11
11
import io .swagger .codegen .v3 .generators .DefaultCodegenConfig ;
12
+ import io .swagger .codegen .v3 .generators .SchemaHandler ;
12
13
import io .swagger .codegen .v3 .generators .util .OpenAPIUtil ;
13
14
import io .swagger .v3 .core .util .Yaml ;
14
15
import io .swagger .v3 .oas .models .OpenAPI ;
15
16
import io .swagger .v3 .oas .models .media .ArraySchema ;
17
+ import io .swagger .v3 .oas .models .media .ComposedSchema ;
16
18
import io .swagger .v3 .oas .models .media .MapSchema ;
17
19
import io .swagger .v3 .oas .models .media .Schema ;
18
20
import org .apache .commons .lang3 .StringUtils ;
@@ -243,12 +245,32 @@ public String getTypeDeclaration(Schema schema) {
243
245
if (schema instanceof ArraySchema ) {
244
246
ArraySchema arraySchema = (ArraySchema ) schema ;
245
247
Schema inner = arraySchema .getItems ();
246
- return "[]" + getTypeDeclaration (inner );
248
+ if (inner instanceof ComposedSchema && schema .getExtensions () != null && schema .getExtensions ().containsKey ("x-schema-name" )) {
249
+ final ComposedSchema composedSchema = (ComposedSchema ) inner ;
250
+ final String prefix ;
251
+ if (composedSchema .getAllOf () != null && !composedSchema .getAllOf ().isEmpty ()) {
252
+ prefix = SchemaHandler .ALL_OF_PREFFIX ;
253
+ } else if (composedSchema .getOneOf () != null && !composedSchema .getOneOf ().isEmpty ()) {
254
+ prefix = SchemaHandler .ONE_OF_PREFFIX ;
255
+ } else {
256
+ prefix = SchemaHandler .ANY_OF_PREFFIX ;
257
+ }
258
+ return "[]" + toModelName (prefix + schema .getExtensions ().get ("x-schema-name" )) + SchemaHandler .ARRAY_ITEMS_SUFFIX ;
259
+ } else {
260
+ return "[]" + getTypeDeclaration (inner );
261
+ }
247
262
} else if (schema instanceof MapSchema && hasSchemaProperties (schema )) {
248
263
MapSchema mapSchema = (MapSchema ) schema ;
249
264
Schema inner = (Schema ) mapSchema .getAdditionalProperties ();
250
265
251
266
return getSchemaType (schema ) + "[string]" + getTypeDeclaration (inner );
267
+ } else if (schema .get$ref () != null ) {
268
+ final String simpleRefName = OpenAPIUtil .getSimpleRef (schema .get$ref ());
269
+ final Schema refSchema = OpenAPIUtil .getSchemaFromName (simpleRefName , this .openAPI );
270
+ if (refSchema != null && (refSchema instanceof ArraySchema || refSchema instanceof MapSchema )) {
271
+ refSchema .addExtension ("x-schema-name" , simpleRefName );
272
+ return getTypeDeclaration (refSchema );
273
+ }
252
274
}
253
275
// Not using the supertype invocation, because we want to UpperCamelize
254
276
// the type.
@@ -271,7 +293,7 @@ public String getSchemaType(Schema schema) {
271
293
272
294
if (schema .get$ref () != null ) {
273
295
final Schema refSchema = OpenAPIUtil .getSchemaFromName (schemaType , this .openAPI );
274
- if (refSchema != null && !isObjectSchema (refSchema )) {
296
+ if (refSchema != null && !isObjectSchema (refSchema ) && refSchema . getEnum () == null ) {
275
297
schemaType = super .getSchemaType (refSchema );
276
298
}
277
299
}
0 commit comments