OpenAPITools / OpenAPITools/openapi-generator
[REQ][JAVA]: Include @JsonProperty to fields in java model class when @lombok.Data is used with Jackson (serializationLibrary)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Hi Team, Thanks for the great contribution of openapi-generator, This project helped me to generate a spring boot application automatically from openapi-spec with in few seconds (instead of manual work which takes minimum 1 or 2 days.)
- When I use the @lombok.Data in additionalModelTypeAnnotations with jackson serializationLibrary, the @JsonProperty annotation is missing in the generated java pojo model (because its included in the setter method of pojo only)
- In my use case I'm using Snake case for schema definition in my openapi spec
Eg: field name
in openapi spec: pet_purchased_date
in java pojo class: petPurchasedDate - It is causing issue when the input is converted to model in java
config:
openApiGenerate {
generatorName = "spring"
inputSpec = "$rootDir/openapi.yaml".toString()
outputDir = "$buildDir/openapi".toString()
apiPackage = "org.petstore.rest"
modelPackage = "org.petstore.interfaces"
apiFilesConstrainedTo = [""]
modelFilesConstrainedTo = [""]
configOptions = [useSpringBoot3: "true", serializationLibrary: "jackson", hideGenerationTimestamp: "true", additionalModelTypeAnnotations: "@lombok.Data; @lombok.AllArgsConstructor; @lombok.NoArgsConstructor;"]
skipValidateSpec = true
globalProperties = [skipFormModel: "false"]
importMappings = [Problem:"org.zalando.problem.Problem", Data:"lombok.Data", NoArgsConstructor:"lombok.NoArgsConstructor", AllArgsConstructor:"lombok.AllArgsConstructor"]
}
Solution
Include the below line as mentioned as per below image in the pojo.mustache
{{#lombok.Data}}{{#jackson}}@JsonProperty("{{baseName}}"){{/jackson}}{{/lombok.Data}}
Thanks
Vishnu
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Java generator's pojo.mustache template and reproduce the provided configuration using the spring generator, Jackson, Lombok @Data, and a snake_case field such as pet_purchased_date. Done means the generated model includes @JsonProperty for fields when Lombok @Data and Jackson are enabled, preserving the OpenAPI field name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100