mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-04-17 06:39:19 +00:00
Compare commits
1 Commits
python-api
...
autofix-sc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6f94c5d8b |
@@ -353,18 +353,22 @@ public class InlineModelResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (schema.getProperties() != null) {
|
} else {
|
||||||
// If non-object type is specified but also properties
|
if (schema.getProperties() != null) {
|
||||||
LOGGER.error("Illegal schema found with non-object type combined with properties," +
|
// If non-object type is specified but also properties
|
||||||
" no properties should be defined:\n " + schema.toString());
|
LOGGER.warn("Illegal schema found with non-object type ({}) combined with properties. Properties automatically removed.", schema.getType());
|
||||||
return;
|
schema.setProperties(null);
|
||||||
} else if (schema.getAdditionalProperties() != null) {
|
return;
|
||||||
// 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 " +
|
if (schema.getAdditionalProperties() != null) {
|
||||||
schema.toString());
|
// If non-object type is specified but also additionalProperties
|
||||||
return;
|
LOGGER.error("Illegal schema found with non-object type ({}) combined with additionalProperties. AdditionalProperties automatically removed.", schema.getType());
|
||||||
|
schema.setAdditionalProperties(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check array items
|
// Check array items
|
||||||
if (ModelUtils.isArraySchema(schema)) {
|
if (ModelUtils.isArraySchema(schema)) {
|
||||||
Schema items = ModelUtils.getSchemaItems(schema);
|
Schema items = ModelUtils.getSchemaItems(schema);
|
||||||
|
|||||||
@@ -1205,4 +1205,13 @@ public class InlineModelResolverTest {
|
|||||||
assertNotNull(allOfRefWithDescriptionAndReadonly.getAllOf());
|
assertNotNull(allOfRefWithDescriptionAndReadonly.getAllOf());
|
||||||
assertEquals(numberRangeRef, ((Schema) allOfRefWithDescriptionAndReadonly.getAllOf().get(0)).get$ref());
|
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");
|
additionalProperties.put(RETURN_SUCCESS_CODE, "true");
|
||||||
Map<String, File> files = generateFromContract("src/test/resources/bugs/issue_12524.json", SPRING_BOOT, additionalProperties);
|
Map<String, File> files = generateFromContract("src/test/resources/bugs/issue_12524.json", SPRING_BOOT, additionalProperties);
|
||||||
|
|
||||||
JavaFileAssert.assertThat(files.get("API01ListOfStuff.java"))
|
// class extending array is no longer generated as it's automatically fixed by inline resolver
|
||||||
.hasImports("com.fasterxml.jackson.annotation.JsonTypeName");
|
// 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 {
|
} finally {
|
||||||
GlobalSettings.reset();
|
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