OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][JAXRS-SPEC] Required fields in oneOf should not be required in @JsonCreator
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Required fields that are specified in a oneOf are currently generated as required in the @JsonCreator constructor.
This incorrectly results in jackson MismatchedInputException when deserializing a valid json.
new ObjectMapper().readValue("{\"a\": 1}", Test.class);
Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Missing required creator property 'b' (index 1)
openapi-generator version
7.11.0
OpenAPI declaration file content or url
components:
schemas:
Test:
type: object
oneOf:
- $ref: "#/components/schemas/TypeA"
- $ref: "#/components/schemas/TypeB"
TypeA:
type: object
properties:
a:
type: integer
required: [a]
TypeB:
type: object
properties:
b:
type: integer
required: [b]
Generates
@JsonCreator
public Test(
@JsonProperty(required = true, value = "a") Integer a,
@JsonProperty(required = true, value = "b") Integer b
) {
this.a = a;
this.b = b;
}
Related issues/PRs
Seems similar to what's been reported in #20513 for kotlin. But in combination with #19578 introduced in 7.11.0 there is significant impact as it causes jackson validation errors at runtime.
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 the supplied OpenAPI declaration and compare the generated Java @JsonCreator parameters for Test, TypeA, and TypeB. Trace where required fields from oneOf schemas become required creator properties; done means deserializing {"a": 1} succeeds without a missing-property exception while preserving validation for genuinely required fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100