Skip to content

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

@jpraet

Description

@jpraet
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions