OpenAPITools / OpenAPITools/openapi-generator
[BUG] array schemas with single non-object allOf entry aren't resolved
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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:
I'll open a PR
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with InlineModelResolver.java around lines 328-335, then reproduce using modules/openapi-generator/src/test/resources/3_0/array_allof_single_type.yaml and the openapi-generator generate command. Compare the existing object handling with this single non-object allOf case. Done means the schema is resolved and generated outputs no longer contain the unresolved array type shown in the Go example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100