OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] Array of oneOf should be possible to be empty
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When using oneOf for an array it generates in a way that array of single value can not be empy. If you leave out the oneOf and have an array of just strings it can be empty.
if (instance instanceof List) {
List<?> list = (List)instance;
if (list.get(0) instanceof sv) {
super.setActualInstance(instance);
return;
}
}
openapi-generator version
7.6.0 -snapshot default library
OpenAPI declaration file content or url
mv:
oneOf:
- $ref: "#/components/schemas/sv"
- type: array
items:
$ref: "#/components/schemas/sv"
sv:
oneOf:
- type: number
format: double
- type: string
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
Allow it to be empty
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 by reproducing the OpenAPI schema from the issue with openapi-generator 7.6.0-SNAPSHOT using the default library, then inspect the generated Java validation around the shown List and oneOf handling. Done means an empty array is accepted while the existing single-value and non-empty array cases remain valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100