mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-01-24 01:37:08 +00:00
Compare commits
1 Commits
r-workflow
...
autofix-sc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6f94c5d8b |
@@ -353,18 +353,22 @@ public class InlineModelResolver {
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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);
|
||||
|
||||
@@ -1205,4 +1205,13 @@ public class InlineModelResolverTest {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2272,8 +2272,12 @@ public class SpringCodegenTest {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
Reference in New Issue
Block a user