openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[REQ][JAVA]: Include @JsonProperty to fields in java model class when @lombok.Data is used with Jackson (serializationLibrary)

Open vishnuloga opened this issue 1 year ago • 1 comments

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.)

  1. 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)
  2. 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
  3. 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}}

image

pojo.mustache.json

Thanks Vishnu

vishnuloga avatar Oct 01 '24 14:10 vishnuloga

same as #18794?

fstorz avatar Jun 10 '25 18:06 fstorz