OpenAPITools / OpenAPITools/openapi-generator

[REQ][JAVA]: Add @com.fasterxml.jackson.annotation.JsonProperty when @lombok.Data is used

Open
#18,794 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

When using @lombok.Data in additionalModelTypeAnnotations, the getters for fields are not generated. While @com.fasterxml.jackson.annotation.JsonProperty is only placed on getter methods, this causes a problem when the property name is in kebab-case rather than the default camel-case.

openapi-generator version

7.6.0

OpenAPI declaration file content or URL

pojo.mustache

Command line used for generation

Regular maven build.

Steps to reproduce

Configuring the maven plugin using the following configOptions:

<configOptions>
    <library>spring-cloud</library>
    <useSpringBoot3>true</useSpringBoot3>
    <useResponseEntity>false</useResponseEntity>
    <bigDeciamlAsString>true</bigDeciamlAsString>
    <dateLibrary>java8-localdatetime</dateLibrary>
    <useEnumCaseInsensitive>true</useEnumCaseInsensitive>
    <configPackage>com.kbakhtiari</configPackage>
    <generatedConstructorWithRequiredArgs>false</generatedConstructorWithRequiredArgs>
    <additionalModelTypeAnnotations>
        @lombok.Data
        @lombok.NoArgsConstructor
        @lombok.AllArgsConstructor
        @lombok.Builder(toBuilder = true)    
    </additionalModelTypeAnnotations>
</configOptions>
Related issues/PRs

N/A

Suggest a fix/enhancement

Adding the following code snippet to pojo.mustache:

{{#lombok.Data}}
@JsonProperty("{{baseName}}")
{{/lombok.Data}}

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 modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache and review how additionalModelTypeAnnotations and @lombok.Data affect generated model properties. Reproduce the kebab-case property scenario with the stated Maven configuration, then verify that generated Java models include the needed JsonProperty annotation and preserve the existing Lombok annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.