OpenAPITools / OpenAPITools/openapi-generator

[BUG] [JAVA] oneOf and required does end up non-nullable where it should be nullable

Open
#17,938 2 comments 3 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

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • [] What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

For properties that are made mutually exclusive using oneOf, the generated pojo is containing @Nonnull and @JsonInclude(value = JsonInclude.Include.ALWAYS) which is wrong. The result of that is that this properties are serialized with a null value altough the should not be serialized at all.

openapi-generator version

v7.3.0 and master

OpenAPI declaration file content or url

https://gist.github.com/david0/1b3d159b4e951e1a589fac596e9a0488

Generation Details

generate -i oneOf-issue.openapi.yaml -g java --library webclient -o out

Steps to reproduce
  1. generate oneOf-issue.openapi.yaml
Related issues/PRs
Suggest a fix

It would be better if required properties would be turned into nullable when inlining them via oneOf.
Maybe even better that that would be to leave the nullable and JsonInclude out in this case and then one could add the required annotations via x-field-extra-annotation, giving more control what is needed in specific cases.

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 with the linked oneOf-issue.openapi.yaml reproduction and run the documented generate -i oneOf-issue.openapi.yaml -g java --library webclient -o out command. Inspect the Java generator's webclient output for the generated POJO annotations; done means mutually exclusive properties are not emitted with incorrect non-null and always-include behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.