OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVA][SPRING] When using lombok generators and `generatedConstructorWithRequiredArgs` build fails

Open
#16,250 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

we use the spring generator with the below config

<openapi.producer.generator.config.additionalModelTypeAnnotations.default>
    @com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true)
    @lombok.Builder(toBuilder = true)
    @lombok.NoArgsConstructor
    @lombok.AllArgsConstructor
</openapi.producer.generator.config.additionalModelTypeAnnotations.default>

to generate constructors & builders.

WIth the new generatedConstructorWithRequiredArgs parameter the build fails because lombok has already generated the constructor. Then the generator attempts to do the same and fails with a constructor already exists error.

openapi-generator version

6.6.0

Suggest a fix

I think it would be best to identify already generated constructors and just ignore them, instead of failing, since ultimately there already is a suitable constructor and hence the goal is achieved.

Not Duplicate

please note I am aware of #15494 and we have applied this workaround, but in my opinion this should work out of the box. Users shouldn't have to configure another property to work around this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Spring generator's handling of generatedConstructorWithRequiredArgs and the additionalModelTypeAnnotations configuration, reproducing the failure with the Lombok constructor annotations shown. Done means the generator builds successfully without reporting a duplicate constructor when Lombok already provides a suitable one.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.