Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][JAVA][JAXRS-SPEC] Required fields in oneOf should not be required in @JsonCreator #20545

Open
jpraet opened this issue Jan 27, 2025 · 0 comments

Comments

@jpraet
Copy link
Contributor

jpraet commented Jan 27, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant