Skip to content

Commit 9b985a2

Browse files
committed
auto fix invalid schemas in inline resolver
1 parent 57752d1 commit 9b985a2

3 files changed

Lines changed: 62 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,16 @@ private void gatherInlineModels(Schema schema, String modelPrefix) {
355355
}
356356
} else if (schema.getProperties() != null) {
357357
// If non-object type is specified but also properties
358-
LOGGER.error("Illegal schema found with non-object type combined with properties," +
359-
" no properties should be defined:\n " + schema.toString());
358+
LOGGER.warn("Illegal schema found with non-object type ({}) combined with properties. Properties automatically removed.", schema.getType());
359+
schema.setProperties(null);
360360
return;
361361
} else if (schema.getAdditionalProperties() != null) {
362362
// If non-object type is specified but also additionalProperties
363-
LOGGER.error("Illegal schema found with non-object type combined with" +
364-
" additionalProperties, no additionalProperties should be defined:\n " +
365-
schema.toString());
363+
LOGGER.error("Illegal schema found with non-object type ({}) combined with additionalProperties. AdditionalProperties automatically removed.", schema.getType());
364+
schema.setAdditionalProperties(null);
366365
return;
367366
}
367+
368368
// Check array items
369369
if (ModelUtils.isArraySchema(schema)) {
370370
Schema items = ModelUtils.getSchemaItems(schema);

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,4 +1205,13 @@ public void doNotWrapSingleAllOfRefs() {
12051205
assertNotNull(allOfRefWithDescriptionAndReadonly.getAllOf());
12061206
assertEquals(numberRangeRef, ((Schema) allOfRefWithDescriptionAndReadonly.getAllOf().get(0)).get$ref());
12071207
}
1208+
1209+
@Test
1210+
public void testNonNullTypeWithProperties() {
1211+
OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/issue_21680_array_with_properties.yaml");
1212+
new InlineModelResolver().flatten(openAPI);
1213+
Schema<?> schema = (Schema<?>) openAPI.getComponents().getSchemas().get("errors");
1214+
assertNotNull(schema);
1215+
assertNull(schema.getProperties());
1216+
}
12081217
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
# Corresponds to bug report 21680: https://github.com/openapitools/openapi-generator/issues/21680
3+
openapi: 3.0.1
4+
info:
5+
title: API that has problem with OpenAPI Generator
6+
version: 1.0.0
7+
paths:
8+
"/forbiddenaccesscsrf":
9+
get:
10+
summary: Forbidden access CSRF
11+
operationId: forbiddenAccessCsrfGet
12+
responses:
13+
'403':
14+
description: Expected response
15+
content:
16+
application/json:
17+
schema:
18+
"$ref": "#/components/schemas/errors"
19+
components:
20+
schemas:
21+
error:
22+
required:
23+
- code
24+
- horodatage
25+
- message
26+
type: object
27+
properties:
28+
code:
29+
type: string
30+
description: Short error description
31+
message:
32+
type: string
33+
description: Complete human readable description
34+
error_uri:
35+
type: string
36+
description: Detailed error description URI
37+
format: uri
38+
horodatage:
39+
type: string
40+
description: Date time of occurence
41+
format: date-time
42+
errors:
43+
type: array
44+
properties:
45+
empty:
46+
type: boolean
47+
items:
48+
"$ref": "#/components/schemas/error"

0 commit comments

Comments
 (0)