forked from loafle/openapi-generator-original
Prevent generating "pattern" and "size" to ENUM (#18658)
This commit is contained in:
parent
2a15270589
commit
4a872a8d69
@ -722,6 +722,16 @@ public class ModelUtils {
|
||||
&& URI_FORMAT.equals(schema.getFormat());
|
||||
}
|
||||
|
||||
public static boolean isEnumSchema(final Schema<?> schema) {
|
||||
// MyEnum:
|
||||
// type: string
|
||||
// enum:
|
||||
// - ENUM_1
|
||||
// - ENUM_2
|
||||
return schema.getEnum() != null
|
||||
&& !schema.getEnum().isEmpty();
|
||||
}
|
||||
|
||||
public static boolean isEmailSchema(Schema schema) {
|
||||
return (schema instanceof EmailSchema) ||
|
||||
// format: email
|
||||
@ -756,7 +766,8 @@ public class ModelUtils {
|
||||
return ModelUtils.isByteArraySchema(schema) ||
|
||||
ModelUtils.isBinarySchema(schema) ||
|
||||
ModelUtils.isUUIDSchema(schema) ||
|
||||
ModelUtils.isURISchema(schema);
|
||||
ModelUtils.isURISchema(schema) ||
|
||||
ModelUtils.isEnumSchema(schema);
|
||||
|
||||
}
|
||||
|
||||
@ -1351,7 +1362,7 @@ public class ModelUtils {
|
||||
once(LOGGER).warn("{} is not defined", schema.get$ref());
|
||||
}
|
||||
return schema;
|
||||
} else if (ref.getEnum() != null && !ref.getEnum().isEmpty()) {
|
||||
} else if (isEnumSchema(ref)) {
|
||||
// top-level enum class
|
||||
return schema;
|
||||
} else if (isArraySchema(ref)) {
|
||||
|
@ -923,6 +923,10 @@ public class AbstractJavaCodegenTest {
|
||||
schema = new Schema<>().type("string").format("binary").pattern("^[a-z]$").maxLength(36);
|
||||
defaultValue = codegen.getTypeDeclaration(schema);
|
||||
Assert.assertEquals(defaultValue, "File");
|
||||
|
||||
schema = new Schema<>().type("string")._enum(List.of("A","B")).pattern("^[a-z]$").maxLength(36);
|
||||
defaultValue = codegen.getTypeDeclaration(schema);
|
||||
Assert.assertEquals(defaultValue, "String");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -945,6 +949,10 @@ public class AbstractJavaCodegenTest {
|
||||
schema = new ArraySchema().items(new Schema<>().type("string").format("binary").pattern("^[a-z]$").maxLength(36));
|
||||
defaultValue = codegen.getTypeDeclaration(schema);
|
||||
Assert.assertEquals(defaultValue, "List<File>");
|
||||
|
||||
schema = new ArraySchema().items(new Schema<>().type("string")._enum(List.of("A","B")).pattern("^[a-z]$").maxLength(36));
|
||||
defaultValue = codegen.getTypeDeclaration(schema);
|
||||
Assert.assertEquals(defaultValue, "List<String>");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user