Open raghuraman1 opened 5 years ago
Hi @wing328 , is the 'unrelated' issue that @raghuraman1 mentioned going to be fixed or has it been fixed via another PR?
I'm seeing the problem too in that right after code generation, there is a maven compile error. I see that the master branch of openapi-generator\modules\openapi-generator\src\main\resources\JavaSpring\libraries\spring-boot\openapi2SpringBoot.mustache doesn't have the commented out code, if that is the desired solution.
@wing328 , @raghuraman1 do we need a separate issue to track the above problem?
do we need a separate issue to track the above problem?
Yes please
I'll close this one as https://github.com/OpenAPITools/openapi-generator/pull/1252 has been merged
Hi, I am using the openapi-generator-maven-plugin with these versions: 3.3.1-SNAPSHOT (thats master ). I came across this bug. Please see code snippet below of the pom.xml alongwith my suggestions for the fix.. Let me know if I should raise a PR.
I have also noted another smaller issue unrelated to this. Thanks. R Please note value of asynch:false .
`
`
For the above configuration in openapi-generator\modules\openapi-generator\src\main\resources\JavaSpring\methodBody.mustache an expression of {{#async}}CompletableFuture.completedFuture({{/async}} should resolve to empty. Unfortunately : In openapi-generator\modules\openapi-generator\src\main\java\org\openapitools\codegen\DefaultGenerator.java the value of async in this.config.additionalProperties() is a string and not a boolean.
This causes wrong code generation.
I can think of a few solutions of which to my mind the most effective one is this: In openapi-generator\modules\openapi-generator\src\main\java\org\openapitools\codegen\DefaultGenerator.java in method public Generator opts(ClientOptInput opts) right after this line "this.config = opts.getConfig();" invoke 'adjustToBoolean("async");'
//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);
` Note: In addition to the above problem and unrelated to this there is a generated code in the generated OpenAPI2SpringBoot.java
@Bean public WebMvcConfigurer webConfigurer() { return new WebMvcConfigurer() { /* @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/*") .allowedOrigins("") .allowedMethods("") .allowedHeaders("Content-Type"); } / }; }
This code is not fully implemented and seems mostly commented. Maven based compilation causes compilation error here. This can be fixed by changing in openapi-generator\modules\openapi-generator\src\main\resources\JavaSpring\libraries\spring-boot\openapi2SpringBoot.mustache the following lines:
@Bean public Web{{^reactive}}Mvc{{/reactive}}{{#reactive}}Flux{{/reactive}}Configurer webConfigurer() { return new Web{{^reactive}}Mvc{{/reactive}} {{#reactive}}Flux{{/reactive}}Configurer{{^java8}}Adapter{{/java8}}() { /* @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/*") .allowedOrigins("") .allowedMethods("") .allowedHeaders("Content-Type"); } / {{^useSpringfox}}
TO
/* @Bean public Web{{^reactive}}Mvc{{/reactive}}{{#reactive}}Flux{{/reactive}}Configurer webConfigurer() { return new Web{{^reactive}}Mvc{{/reactive}}{{#reactive}}Flux{{/reactive}}Configurer{{^java8}}Adapter{{/java8}}() { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/*") .allowedOrigins("") .allowedMethods("*") .allowedHeaders("Content-Type"); } {{^useSpringfox}}
{{/useSpringfox}} }; } */
I can include this change also in the PR Note: I have not yet learnt how to show the code blocks properly in this issue editor. I hope everything is clear in spite of that.