simplify enum of string & string to enum of string (#15149)

This commit is contained in:
William Cheng 2023-04-07 15:54:42 +08:00 committed by GitHub
parent bda2e4a167
commit e8e62ccadb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -598,7 +598,7 @@ public class OpenAPINormalizer {
/**
* If the schema is anyOf and the sub-schemas are either string or enum of string,
* then simplify it to just string as many generators do not yet support anyOf.
* then simplify it to just enum of string as many generators do not yet support anyOf.
*
* @param schema Schema
* @return Schema
@ -624,12 +624,12 @@ public class OpenAPINormalizer {
s0 = ModelUtils.getReferencedSchema(openAPI, s0);
s1 = ModelUtils.getReferencedSchema(openAPI, s1);
// find the string schema (not enum)
// find the string schema (enum)
if (s0 instanceof StringSchema && s1 instanceof StringSchema) {
if (((StringSchema) s0).getEnum() != null) { // s0 is enum, s1 is string
result = (StringSchema) s1;
} else if (((StringSchema) s1).getEnum() != null) { // s1 is enum, s0 is string
result = (StringSchema) s0;
} else if (((StringSchema) s1).getEnum() != null) { // s1 is enum, s0 is string
result = (StringSchema) s1;
} else { // both are string
result = schema;
}

View File

@ -132,6 +132,7 @@ public class OpenAPINormalizerTest {
Schema schema3 = openAPI.getComponents().getSchemas().get("AnyOfTest");
assertNull(schema3.getAnyOf());
assertTrue(schema3 instanceof StringSchema);
assertTrue(schema3.getEnum().size() > 0);
}
@Test