Skip to content

[BUG][Java][Spring] Always generate the default constructor if it is the only constructor #24747

Description

@anthonyvdotbe

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

The generator does not generate the default constructor if it is the only constructor. This is problematic, e.g., when such a class is in a package that is exported by a Java module and the module is compiled with javac -Xlint:all -Werror, because it fails the lint check missing-explicit-ctor.

openapi-generator version

v7.24.0

OpenAPI declaration file content or url

openapi.yaml

Generation Details

config.json

Steps to reproduce
  • in a directory X, create openapi.yaml and config.json with the contents as above
  • from within X, run docker run --rm -v .:/local openapitools/openapi-generator-cli:v7.24.0 generate --strict-spec true --input-spec /local/openapi.yaml --generator-name spring --config /local/config.json --output /local/output
  • open .\output\src\main\java\org\openapitools\model\Foo.java

actual: the default constructor is not generated

expected: the default constructor is generated

Related issues/PRs
Suggest a fix

I assume this will require an update to the pojo.mustache template.

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