swagger-codegen
swagger-codegen copied to clipboard
[JAVA] Snake case field name gets converted to camel case with codegen
Description
Our POJO has some fields which look like this
@Getter
@Setter
public class Error {
String errorName;
String errorCode;
String error_code;
}
Using mvn plugin we generate the swagger document (say api-service.json) and it creates the fields(errorCode and error_code) as expected like this (Adding just a snippet)
....
"errorCode" : {
"type" : "string"
},
"errorName" : {
"type" : "string"
},
"error_code" : {
"type" : "string"
},
....
Now, when the client uses codegen (command below), the field error_code and its corresponding getters and setters are converted to errorCode and clashes with the already existing field , thus creating compilation error.
Generated Java file
....
@SerializedName("errorCode")
private String errorCode = null;
@SerializedName("error_code")
private String errorCode = null;
....
Swagger-codegen version
3.0.35
Command line used for generation
swagger-codegen generate \
-i /Users/sh/api-service.json \
--api-package com.company.services \
--model-package com.company.services.dto \
--invoker-package com.company.services.app \
--group-id com.company.services \
--artifact-id service-api \
--artifact-version 0.0.1-SNAPSHOT \
-l java \
-o output-april-2023
How do I retain the original field name of error_code in the generated code after running swagger-codegen ?
have the same problem +1