@@ -889,7 +889,7 @@ public static boolean isFreeFormObject(Schema schema, OpenAPI openAPI) {
889889 if (schema .getAdditionalProperties () instanceof Boolean && (Boolean ) schema .getAdditionalProperties ()) {
890890 return true ;
891891 } else if (schema .getAdditionalProperties () instanceof JsonSchema ) {
892- return true ;
892+ return ! ModelUtils . hasEnumPropertyNames ( schema ) ;
893893 } else if (schema .getTypes () != null ) {
894894 if (schema .getTypes ().size () == 1 ) { // types = [object]
895895 return SchemaTypeUtil .OBJECT_TYPE .equals (schema .getTypes ().iterator ().next ());
@@ -937,7 +937,7 @@ public static boolean isFreeFormObject(Schema schema, OpenAPI openAPI) {
937937 return objSchema .getProperties () == null || objSchema .getProperties ().isEmpty ();
938938 } else if (addlProps instanceof Schema ) {
939939 // additionalProperties defined as {}
940- return addlProps .getType () == null && addlProps .get$ref () == null && (addlProps .getProperties () == null || addlProps .getProperties ().isEmpty ());
940+ return addlProps .getType () == null && addlProps .get$ref () == null && (addlProps .getProperties () == null || addlProps .getProperties ().isEmpty ()) && ! ModelUtils . hasEnumPropertyNames ( schema ) ;
941941 }
942942 }
943943 }
@@ -963,7 +963,7 @@ public static boolean shouldGenerateMapModel(Schema schema) {
963963 // A composed schema (allOf, oneOf, anyOf) is considered a Map schema if the additionalproperties attribute is set
964964 // for that composed schema. However, in the case of a composed schema, the properties are defined or referenced
965965 // in the inner schemas, and the outer schema does not have properties.
966- return ModelUtils .isGenerateAliasAsModel (schema ) || ModelUtils .isComposedSchema (schema ) || !(schema .getProperties () == null || schema .getProperties ().isEmpty ());
966+ return ModelUtils .isGenerateAliasAsModel (schema ) || ModelUtils .isComposedSchema (schema ) || !(schema .getProperties () == null || schema .getProperties ().isEmpty ()) || ModelUtils . hasEnumPropertyNames ( schema ) ;
967967 }
968968
969969 public static boolean shouldGenerateArrayModel (Schema schema ) {
@@ -2158,6 +2158,13 @@ public static boolean hasAnyOf(Schema schema) {
21582158 return false ;
21592159 }
21602160
2161+ public static boolean hasEnumPropertyNames (Schema schema ) {
2162+ if (schema == null || schema .getPropertyNames () == null ) {
2163+ return false ;
2164+ }
2165+ return !schema .getPropertyNames ().getEnum ().isEmpty ();
2166+ }
2167+
21612168 /**
21622169 * Returns schema type.
21632170 * For 3.1 spec, return the first one.
0 commit comments