Skip to content

Commit ff8fa40

Browse files
authored
fix object and complex compposed schema check (#18352)
1 parent 172c4d1 commit ff8fa40

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/utils/ModelUtils.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public static boolean isObjectSchema(Schema schema) {
460460

461461
return (schema instanceof ObjectSchema) ||
462462
// must not be a map
463-
(SchemaTypeUtil.OBJECT_TYPE.equals(schema.getType()) && !(schema instanceof MapSchema)) ||
463+
(SchemaTypeUtil.OBJECT_TYPE.equals(schema.getType()) && !(ModelUtils.isMapSchema(schema))) ||
464464
// must have at least one property
465465
(schema.getType() == null && schema.getProperties() != null && !schema.getProperties().isEmpty());
466466
}
@@ -509,10 +509,6 @@ public static boolean isComposedSchema(Schema schema) {
509509
* @return true if the specified schema is a Composed schema.
510510
*/
511511
public static boolean isComplexComposedSchema(Schema schema) {
512-
if (!(schema instanceof ComposedSchema)) {
513-
return false;
514-
}
515-
516512
int count = 0;
517513

518514
if (schema.getAllOf() != null && !schema.getAllOf().isEmpty()) {

modules/openapi-generator/src/test/java/org/openapitools/codegen/utils/ModelUtilsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,5 +384,11 @@ public void test31Schemas() {
384384
Assert.assertFalse(anyof2.getAnyOf().isEmpty());
385385
Assert.assertTrue(ModelUtils.hasAnyOf(anyof2));
386386
Assert.assertTrue(ModelUtils.isAnyOf(anyof2));
387+
388+
Schema objectSchema = ModelUtils.getSchema(openAPI, "ObjectSchema");
389+
Assert.assertTrue(ModelUtils.isMapSchema(objectSchema));
390+
391+
Schema complexComposedSchema = ModelUtils.getSchema(openAPI, "ComplexComposedSchema");
392+
Assert.assertTrue(ModelUtils.isComplexComposedSchema(complexComposedSchema));
387393
}
388394
}

modules/openapi-generator/src/test/resources/3_1/schema.yaml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,19 @@ components:
6464
oneof1:
6565
oneOf:
6666
- type: string
67-
- type: integer
67+
- type: integer
68+
ObjectSchema:
69+
type: object
70+
additionalProperties: false
71+
properties:
72+
name:
73+
type: string
74+
address:
75+
type: string
76+
ComplexComposedSchema:
77+
oneOf:
78+
- type: string
79+
- type: integer
80+
anyOf:
81+
- type: string
82+
- type: number

0 commit comments

Comments
 (0)