mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
fix object and complex compposed schema check (#18352)
This commit is contained in:
parent
172c4d11b4
commit
ff8fa40808
@ -460,7 +460,7 @@ public class ModelUtils {
|
|||||||
|
|
||||||
return (schema instanceof ObjectSchema) ||
|
return (schema instanceof ObjectSchema) ||
|
||||||
// must not be a map
|
// 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
|
// must have at least one property
|
||||||
(schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
|
(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.
|
* @return true if the specified schema is a Composed schema.
|
||||||
*/
|
*/
|
||||||
public static boolean isComplexComposedSchema(Schema schema) {
|
public static boolean isComplexComposedSchema(Schema schema) {
|
||||||
if (!(schema instanceof ComposedSchema)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if (schema.getAllOf() != null && !schema.getAllOf().isEmpty()) {
|
if (schema.getAllOf() != null && !schema.getAllOf().isEmpty()) {
|
||||||
|
@ -384,5 +384,11 @@ public class ModelUtilsTest {
|
|||||||
Assert.assertFalse(anyof2.getAnyOf().isEmpty());
|
Assert.assertFalse(anyof2.getAnyOf().isEmpty());
|
||||||
Assert.assertTrue(ModelUtils.hasAnyOf(anyof2));
|
Assert.assertTrue(ModelUtils.hasAnyOf(anyof2));
|
||||||
Assert.assertTrue(ModelUtils.isAnyOf(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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,4 +64,19 @@ components:
|
|||||||
oneof1:
|
oneof1:
|
||||||
oneOf:
|
oneOf:
|
||||||
- type: string
|
- 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
|
Loading…
x
Reference in New Issue
Block a user