I used Swagger-codegen-cli to generate java-client code with Swagger Spec provided by an external service.
When I upgraded the version of swagger-codegen-cli and recreated it, the getter of Boolean changed to ʻisXXXinstead of
getXXX`.
--I used v2.2.3 of swagger-codegen-cli before, but the new Swagger Spec doesn't generate it correctly. (Gets a build error) --Changed to v2.2.3-> v2.3.1 (current stable)
Add -t
when executing
#Example
# -t:Specify the folder where the template is located.Priority is given to the template file that exists in template.
java -jar swagger-codegen-cli.jar generate -l java -t ./template -o swagger-java-client
The location of the original template file is on github at swagger-codegen / modules / swagger-codegen / src / main / resources / Java /
The template file I want to overwrite this time is pojo.mustache. Looking at the getter part
public {{{datatypeWithEnum}}} {{#isBoolean}}is{{/isBoolean}}{{getter}}() {
return {{name}};
}
{{^isReadOnly}}
There is a place where it is, so fix it as follows
{{#isBoolean}}
public {{{datatypeWithEnum}}} get{{getter}}() {
return {{name}};
}
{{/isBoolean}}
{{!Get is set without writing get except for Boolean}}
{{^isBoolean}}
public {{{datatypeWithEnum}}} {{getter}}() {
return {{name}};
}
{{/isBoolean}}
{{^isReadOnly}}
This time, I'm having trouble with the generated code, so I overwrote the template. You can also customize it to your liking.
In v2.3.1, there is no choice but to overwrite with the template file, but in the next version, config may be able to determine the Boolean prefix. (As of April 13, 2018)