Skip to content

[BUG][Java] Required fields not honored in @JsonProperty annotations #21060

@elagerho

Description

@elagerho

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?
Description

The Pojo and Jackson annotation templates are not honoring required fields in the spec. Adjacent @JsonBProperty annotations do.

Expected annotations with required fields:

@JsonProperty(value = JSON_PROPERTY_NAME, required = true)

Actual annotations

@JsonProperty(JSON_PROPERTY_NAME)

openapi-generator version

master

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: 'Some API'
  version: 1.0.0
servers:
  - url: 'https://localhost'
paths:
  /v1/some_path:
    get:
      responses:
        '200':
          content:
            application/json:
              schema:
                type: object
                properties:
                  foo:
                    type: string
                required:
                  - foo
          description: "some description"
Steps to reproduce
  1. Have a spec with any required field
  2. Run the Java codegen with Jackson serialization
  3. See the generated model is not honoring required in the @JsonProperty annotation
Related issues/PRs

Have searched but not found any.

Suggest a fix

I will submit a PR with changes for further consideration.

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