diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java index d3317375321b..1b1dd2c6538e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java @@ -1280,6 +1280,9 @@ private Schema processNormalize31Spec(Schema schema, Set visitedSchemas) Schema updatedItems = normalizeSchema(schema.getItems(), visitedSchemas); as.setItems(updatedItems); } + } else { + // when items is not defined, default to any type + as.setItems(new Schema()); } return as; diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java index 70c04397e233..3537cc5b8974 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java @@ -600,6 +600,11 @@ public void testOpenAPINormalizerProcessingArraySchema31Spec() { assertEquals(((Schema) schema5.getProperties().get("arrayOfStrings")).getItems().getType(), null); assertEquals(((Schema) schema5.getProperties().get("arrayOfStrings")).getItems().getTypes().contains("string"), true); + Schema schema7 = openAPI.getComponents().getSchemas().get("ArrayWithPrefixItems"); + assertEquals(((Schema) schema7.getProperties().get("with_prefixitems")).getItems(), null); + assertNotEquals(((Schema) schema7.getProperties().get("with_prefixitems")).getPrefixItems(), null); + assertEquals(((Schema) schema7.getProperties().get("without_items")).getItems(), null); + Map inputRules = Map.of("NORMALIZE_31SPEC", "true"); OpenAPINormalizer openAPINormalizer = new OpenAPINormalizer(openAPI, inputRules); openAPINormalizer.normalize(); @@ -622,6 +627,11 @@ public void testOpenAPINormalizerProcessingArraySchema31Spec() { assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getItems().getTypes().contains("string"), true); assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getItems().getType(), "string"); assertEquals(((Schema) schema6.getProperties().get("arrayOfStrings")).getType(), "array"); + + Schema schema8 = openAPI.getComponents().getSchemas().get("ArrayWithPrefixItems"); + assertNotEquals(((Schema) schema8.getProperties().get("with_prefixitems")).getItems(), null); + assertEquals(((Schema) schema8.getProperties().get("with_prefixitems")).getPrefixItems(), null); + assertNotEquals(((Schema) schema8.getProperties().get("without_items")).getItems(), null); } @Test diff --git a/modules/openapi-generator/src/test/resources/3_1/issue_18291.yaml b/modules/openapi-generator/src/test/resources/3_1/issue_18291.yaml index 8f5b9db4e1a8..8ea8a90357f6 100644 --- a/modules/openapi-generator/src/test/resources/3_1/issue_18291.yaml +++ b/modules/openapi-generator/src/test/resources/3_1/issue_18291.yaml @@ -30,7 +30,20 @@ components: type: array items: type: string - Bar: allOf: - - $ref: '#/components/schemas/Foo' \ No newline at end of file + - $ref: '#/components/schemas/Foo' + ArrayWithPrefixItems: + type: object + properties: + with_prefixitems: + type: array + prefixItems: + - type: number + title: Longitude + - type: number + title: Latitude + maxItems: 2 + minItems: 2 + without_items: + type: array