Open nokhod opened 4 weeks ago
@nokhod, @Jsonproperty
can put on field, not only getter method, you just need set x-field-extra-annotation
, for example the User object in OpenAPI spec 3.0
User:
type: object
properties:
id:
type: integer
format: int64
example: 10
username:
type: string
example: theUser
firstName:
type: string
example: John
x-field-extra-annotation: |-
@JsonProperty("first_name")
lastName:
type: string
example: James
x-field-extra-annotation: |-
@JsonProperty("last_name")
email:
type: string
example: john@email.com
password:
type: string
example: '12345'
phone:
type: string
example: '12345'
userStatus:
type: integer
description: User Status
format: int32
example: 1
xml:
name: user
the generated model is
/**
* User
*/
@lombok.Data
@lombok.NoArgsConstructor
@lombok.AllArgsConstructor
@lombok.Builder(toBuilder = true)
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.7.0-SNAPSHOT")
public class User {
private Long id;
private String username;
@JsonProperty("first_name")
private String firstName;
@JsonProperty("last_name")
private String lastName;
private String email;
private String password;
private String phone;
private Integer userStatus;
}
Hi @dabdirb Unfortunately, the openapi specs are not in my control to alter.
Description
When using
@lombok.Data
inadditionalModelTypeAnnotations
, 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:
Related issues/PRs
N/A
Suggest a fix/enhancement
Adding the following code snippet to pojo.mustache: