fix object and complex compposed schema check (#18352)

This commit is contained in:
William Cheng 2024-04-11 14:26:45 +08:00 committed by GitHub
parent 172c4d11b4
commit ff8fa40808
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 6 deletions

View File

@ -460,7 +460,7 @@ public class ModelUtils {
return (schema instanceof ObjectSchema) ||
// must not be a map
(SchemaTypeUtil.OBJECT_TYPE.equals(schema.getType()) && !(schema instanceof MapSchema)) ||
(SchemaTypeUtil.OBJECT_TYPE.equals(schema.getType()) && !(ModelUtils.isMapSchema(schema))) ||
// must have at least one property
(schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
}
@ -509,10 +509,6 @@ public class ModelUtils {
* @return true if the specified schema is a Composed schema.
*/
public static boolean isComplexComposedSchema(Schema schema) {
if (!(schema instanceof ComposedSchema)) {
return false;
}
int count = 0;
if (schema.getAllOf() != null && !schema.getAllOf().isEmpty()) {

View File

@ -384,5 +384,11 @@ public class ModelUtilsTest {
Assert.assertFalse(anyof2.getAnyOf().isEmpty());
Assert.assertTrue(ModelUtils.hasAnyOf(anyof2));
Assert.assertTrue(ModelUtils.isAnyOf(anyof2));
Schema objectSchema = ModelUtils.getSchema(openAPI, "ObjectSchema");
Assert.assertTrue(ModelUtils.isMapSchema(objectSchema));
Schema complexComposedSchema = ModelUtils.getSchema(openAPI, "ComplexComposedSchema");
Assert.assertTrue(ModelUtils.isComplexComposedSchema(complexComposedSchema));
}
}

View File

@ -64,4 +64,19 @@ components:
oneof1:
oneOf:
- type: string
- type: integer
- type: integer
ObjectSchema:
type: object
additionalProperties: false
properties:
name:
type: string
address:
type: string
ComplexComposedSchema:
oneOf:
- type: string
- type: integer
anyOf:
- type: string
- type: number