Description
When an array schema contains an allOf definition with just a single element (that is not an object), it is not resolved, even though this can safely be unwrapped. This leads to type resolution errors in generated code. Other composed schemas such as oneOf are handled correctly.
openapi-generator version
v7.22.0
OpenAPI declaration file content or url
openapi: 3.0.0
info:
title: Test
version: 1.0.0
paths: {}
components:
schemas:
Data:
type: object
properties:
outer:
type: array
items:
allOf:
- type: array
items:
type: string
Generation Details
It happens with all generated outputs, many languages can't compile the generated code. E.g. go:
// Data struct for Data
type Data struct {
Outer []Array `json:"outer,omitempty"`
}
Steps to reproduce
run openapi-generator with:
openapi-generator generate -i modules/openapi-generator/src/test/resources/3_0/array_allof_single_type.yaml -o out/ -g <anything>
Related issues/PRs
#23838
Suggest a fix
Basically needs analog handling to the object case:
|
} else if (ModelUtils.isComposedSchema(prop)) { |
|
if (prop.getAllOf() != null && prop.getAllOf().size() == 1 && |
|
!(((Schema) prop.getAllOf().get(0)).getType() == null || |
|
"object".equals(((Schema) prop.getAllOf().get(0)).getType()))) { |
|
// allOf with only 1 type (non-model) |
|
LOGGER.info("allOf schema used by the property `{}` replaced by its only item (a type)", propName); |
|
props.put(propName, (Schema) prop.getAllOf().get(0)); |
|
} |
I'll open a PR
Description
When an array schema contains an
allOfdefinition with just a single element (that is not an object), it is not resolved, even though this can safely be unwrapped. This leads to type resolution errors in generated code. Other composed schemas such asoneOfare handled correctly.openapi-generator version
v7.22.0
OpenAPI declaration file content or url
Generation Details
It happens with all generated outputs, many languages can't compile the generated code. E.g. go:
Steps to reproduce
run openapi-generator with:
openapi-generator generate -i modules/openapi-generator/src/test/resources/3_0/array_allof_single_type.yaml -o out/ -g <anything>Related issues/PRs
#23838
Suggest a fix
Basically needs analog handling to the object case:
openapi-generator/modules/openapi-generator/src/main/java/org/openapitools/codegen/InlineModelResolver.java
Lines 328 to 335 in 0b1ac88
I'll open a PR