OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] Array of oneOf should be possible to be empty

Open
#18,534 1 comment 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.