@@ -501,6 +501,23 @@ public String getTypeString(Schema p, String prefix, String suffix) {
501501 if (suffix == ")" ) {
502502 typeSuffix = "," + suffix ;
503503 }
504+
505+ // XXX - (1) Q&D fix to make sure that 'enum' string/integer/... type aliases are properly converted:
506+ //
507+ // FIXME - Introducing this poses a warning during codegen:
508+ // WARN o.o.codegen.DefaultCodegen - allOf with multiple schemas defined. Using only the first one: <some_type>.
509+ // To fully utilize allOf, please use $ref instead of inline schema definition
510+ //
511+ // It seems to work though...
512+ //
513+ Schema referencedSchema = ModelUtils .getReferencedSchema (this .openAPI , p );
514+ if (ModelUtils .isEnum (referencedSchema )) {
515+ LOGGER .info ("Referenced schema '" + getSimpleTypeDeclaration (p ) + "' is an enum of type '" + referencedSchema .getType () + "' => '" + getSimpleTypeDeclaration (referencedSchema ) + "' (" + referencedSchema .getEnum () + "). Adding referenced type." );
516+ typeSuffix = ", " + getSimpleTypeDeclaration (referencedSchema ) + suffix ;
517+ } else {
518+ LOGGER .debug ("Referenced schema '" + getSimpleTypeDeclaration (p ) + "' is not an enum (type '" + referencedSchema .getType () + "' => '" + getSimpleTypeDeclaration (referencedSchema ) + "')" );
519+ }
520+
504521 if (ModelUtils .isNullable (p )) {
505522 typeSuffix = ", none_type" + suffix ;
506523 }
@@ -519,6 +536,23 @@ public String getTypeString(Schema p, String prefix, String suffix) {
519536 return prefix + "[" + getTypeString (inner , "(" , ")" ) + "]" + typeSuffix ;
520537 }
521538 String baseType = getSimpleTypeDeclaration (p );
539+
540+ // XXX - (2) Alternative Q&D fix for 'enum' conversions:
541+ //
542+ // FIXME - Introducing this poses a warning during codegen:
543+ // WARN o.o.codegen.DefaultCodegen - allOf with multiple schemas defined. Using only the first one: <some_type>.
544+ // To fully utilize allOf, please use $ref instead of inline schema definition
545+ //
546+ // It seems to work though...
547+ //
548+ // Schema referencedSchema = ModelUtils.getReferencedSchema(this.openAPI, p);
549+ // if (ModelUtils.isEnum(referencedSchema)) {
550+ // LOGGER.info("Referenced schema '" + baseType + "' is an enum of type '" + referencedSchema.getType() + "' => '" + getSimpleTypeDeclaration(referencedSchema) + "' (" + referencedSchema.getEnum() + "). Setting baseType as its referenced type.");
551+ // baseType = getSimpleTypeDeclaration(referencedSchema);
552+ // } else {
553+ // LOGGER.debug("Referenced schema '" + baseType + "' is not an enum (type '" + referencedSchema.getType() + "' => '" + getSimpleTypeDeclaration(referencedSchema) + "')");
554+ // }
555+
522556 if (baseType == "file" ) {
523557 baseType = "file_type" ;
524558 }
0 commit comments