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());
|
&& 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) {
|
public static boolean isEmailSchema(Schema schema) {
|
||||||
return (schema instanceof EmailSchema) ||
|
return (schema instanceof EmailSchema) ||
|
||||||
// format: email
|
// format: email
|
||||||
@ -756,7 +766,8 @@ public class ModelUtils {
|
|||||||
return ModelUtils.isByteArraySchema(schema) ||
|
return ModelUtils.isByteArraySchema(schema) ||
|
||||||
ModelUtils.isBinarySchema(schema) ||
|
ModelUtils.isBinarySchema(schema) ||
|
||||||
ModelUtils.isUUIDSchema(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());
|
once(LOGGER).warn("{} is not defined", schema.get$ref());
|
||||||
}
|
}
|
||||||
return schema;
|
return schema;
|
||||||
} else if (ref.getEnum() != null && !ref.getEnum().isEmpty()) {
|
} else if (isEnumSchema(ref)) {
|
||||||
// top-level enum class
|
// top-level enum class
|
||||||
return schema;
|
return schema;
|
||||||
} else if (isArraySchema(ref)) {
|
} else if (isArraySchema(ref)) {
|
||||||
|
@ -923,6 +923,10 @@ public class AbstractJavaCodegenTest {
|
|||||||
schema = new Schema<>().type("string").format("binary").pattern("^[a-z]$").maxLength(36);
|
schema = new Schema<>().type("string").format("binary").pattern("^[a-z]$").maxLength(36);
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "File");
|
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
|
@Test
|
||||||
@ -945,6 +949,10 @@ public class AbstractJavaCodegenTest {
|
|||||||
schema = new ArraySchema().items(new Schema<>().type("string").format("binary").pattern("^[a-z]$").maxLength(36));
|
schema = new ArraySchema().items(new Schema<>().type("string").format("binary").pattern("^[a-z]$").maxLength(36));
|
||||||
defaultValue = codegen.getTypeDeclaration(schema);
|
defaultValue = codegen.getTypeDeclaration(schema);
|
||||||
Assert.assertEquals(defaultValue, "List<File>");
|
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
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user