Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -353,18 +353,22 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
}
}
}
} else if (schema.getProperties() != null) {
// If non-object type is specified but also properties
LOGGER.error("Illegal schema found with non-object type combined with properties," +
" no properties should be defined:\n " + schema.toString());
return;
} else if (schema.getAdditionalProperties() != null) {
// If non-object type is specified but also additionalProperties
LOGGER.error("Illegal schema found with non-object type combined with" +
" additionalProperties, no additionalProperties should be defined:\n " +
schema.toString());
return;
} else {
if (schema.getProperties() != null) {
// If non-object type is specified but also properties
LOGGER.warn("Illegal schema found with non-object type ({}) combined with properties. Properties automatically removed.", schema.getType());
schema.setProperties(null);
return;
}

if (schema.getAdditionalProperties() != null) {
// If non-object type is specified but also additionalProperties
LOGGER.error("Illegal schema found with non-object type ({}) combined with additionalProperties. AdditionalProperties automatically removed.", schema.getType());
schema.setAdditionalProperties(null);
return;
}
}

// Check array items
if (ModelUtils.isArraySchema(schema)) {
Schema items = ModelUtils.getSchemaItems(schema);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,4 +1205,13 @@ public void doNotWrapSingleAllOfRefs() {
assertNotNull(allOfRefWithDescriptionAndReadonly.getAllOf());
assertEquals(numberRangeRef, ((Schema) allOfRefWithDescriptionAndReadonly.getAllOf().get(0)).get$ref());
}

@Test
public void testNonNullTypeWithProperties() {
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue_21680_array_with_properties.yaml");
new InlineModelResolver().flatten(openAPI);
Schema<?> schema = (Schema<?>) openAPI.getComponents().getSchemas().get("errors");
assertNotNull(schema);
assertNull(schema.getProperties());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2272,8 +2272,12 @@ public void testResponseWithArray_issue12524() throws Exception {
additionalProperties.put(RETURN_SUCCESS_CODE, "true");
Map<String, File> files = generateFromContract("src/test/resources/bugs/issue_12524.json", SPRING_BOOT, additionalProperties);

JavaFileAssert.assertThat(files.get("API01ListOfStuff.java"))
.hasImports("com.fasterxml.jackson.annotation.JsonTypeName");
// class extending array is no longer generated as it's automatically fixed by inline resolver
// by removing the properties for array type
//JavaFileAssert.assertThat(files.get("API01ListOfStuff.java"))
// .hasImports("com.fasterxml.jackson.annotation.JsonTypeName");
File notExisting = files.get("API01ListOfStuff.java");
assertThat(notExisting).isNull();
} finally {
GlobalSettings.reset();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
# Corresponds to bug report 21680: https://github.com/openapitools/openapi-generator/issues/21680
openapi: 3.0.1
info:
title: API that has problem with OpenAPI Generator
version: 1.0.0
paths:
"/forbiddenaccesscsrf":
get:
summary: Forbidden access CSRF
operationId: forbiddenAccessCsrfGet
responses:
'403':
description: Expected response
content:
application/json:
schema:
"$ref": "#/components/schemas/errors"
components:
schemas:
error:
required:
- code
- horodatage
- message
type: object
properties:
code:
type: string
description: Short error description
message:
type: string
description: Complete human readable description
error_uri:
type: string
description: Detailed error description URI
format: uri
horodatage:
type: string
description: Date time of occurence
format: date-time
errors:
type: array
properties:
empty:
type: boolean
items:
"$ref": "#/components/schemas/error"
Loading