swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
Hi,
I am using the swagger-codegen-maven-plugin with these versions: 2.3.1 and 2.4.0-SNAPSHOT (thats master i think).
I came across this bug. Please see code snippet below of the pom.xml alongwith my suggestions for the fix.. I think its not resolved yet.
If you feel its already fixed please excuse.
Thanks.
R
Please note value of asynch: false.
For the above configuration in swagger-codegen\src\main\resources\JavaSpring\apiDelegate.mustache an expression of {{#async}}CompletableFuture.completedFuture({{/async}} should resolve to empty. Unfortunately : In swagger-codegen\src\main\java\io\swagger\codegen\DefaultGenerator.java the value of async in this.config.additionalProperties() is a string.
This causes wrong code generation.
I can think of three solutions:
In swagger-codegen\src\main\java\io\swagger\codegen\languages\SpringCodegen.java in public void processOpts() method change these lines:
if (additionalProperties.containsKey(ASYNC)) {
this.setAsync(Boolean.valueOf(additionalProperties.get(ASYNC).toString()));
}
TO
if (additionalProperties.containsKey(ASYNC)) {
this.setAsync(Boolean.valueOf(additionalProperties.get(ASYNC).toString()));
convertPropertyToBooleanAndWriteBack(ASYNC);
}
Another way is in swagger-codegen\src\main\java\io\swagger\codegen\DefaultGenerator.java in method public Generator opts(ClientOptInput opts) right after this line
"this.config = opts.getConfig();"
invoke
'adjustToBoolean("async");'
this second approach has benefit that you can use it from one place than do this change from many places.
I also think there may be other similar boolean properties that need similar handling.
//new method
I can confirm that this issue still exists in version 3.0.11. When the async option is set to anything ("true", "false", "asdf", ...), the {{#async}} ... {{/async}} sections are added.
Hi, I am using the swagger-codegen-maven-plugin with these versions: 2.3.1 and 2.4.0-SNAPSHOT (thats master i think). I came across this bug. Please see code snippet below of the pom.xml alongwith my suggestions for the fix.. I think its not resolved yet. If you feel its already fixed please excuse. Thanks. R Please note value of asynch:false .
`
`
For the above configuration in swagger-codegen\src\main\resources\JavaSpring\apiDelegate.mustache an expression of {{#async}}CompletableFuture.completedFuture({{/async}} should resolve to empty. Unfortunately : In swagger-codegen\src\main\java\io\swagger\codegen\DefaultGenerator.java the value of async in this.config.additionalProperties() is a string.
This causes wrong code generation.
I can think of three solutions:
In swagger-codegen\src\main\java\io\swagger\codegen\languages\SpringCodegen.java in public void processOpts() method change these lines: if (additionalProperties.containsKey(ASYNC)) { this.setAsync(Boolean.valueOf(additionalProperties.get(ASYNC).toString())); } TO if (additionalProperties.containsKey(ASYNC)) { this.setAsync(Boolean.valueOf(additionalProperties.get(ASYNC).toString())); convertPropertyToBooleanAndWriteBack(ASYNC); }
Another way is in swagger-codegen\src\main\java\io\swagger\codegen\DefaultGenerator.java in method public Generator opts(ClientOptInput opts) right after this line "this.config = opts.getConfig();" invoke 'adjustToBoolean("async");' this second approach has benefit that you can use it from one place than do this change from many places. I also think there may be other similar boolean properties that need similar handling. //new method
` public void adjustToBoolean(String propertyName) { Object object = this.config.additionalProperties().get(propertyName); Boolean val=Boolean.FALSE; if(object!=null) { if(object instanceof String) { String string=(String) object; if(string.equalsIgnoreCase("true")) { val=true; } else { val=Boolean.FALSE; } } else if(object instanceof Boolean) { val=(Boolean) object; } else { val=Boolean.TRUE; } } else { val=Boolean.FALSE; } this.config.additionalProperties().put(propertyName, val);
` Adding a a small google doc with more details using the 2nd approach https://docs.google.com/document/d/1N7ASyYPAuk5gO_kqcggXHOG_w5nGlKlToy2H1bbG6Tg/edit?usp=sharing