Bug Report Checklist
Description
The files generated from resttemplate are importing org.springframework.stereotype.Component even when generateClientAsBean property is set to false (default).
|
import org.springframework.stereotype.Component; |
|
import org.springframework.stereotype.Component; |
According to the docs, the @Component annotation will be only added if generateClientAsBean is set to true
So, to fix the issue, you just need to replace the current content with bellow suggestion in both places:
{{#generateClientAsBean}}
import org.springframework.stereotype.Component;
{{/generateClientAsBean}}
openapi-generator version
I'm currently using below settings - however I can reproduce the issue in prior versions
Generator: java
Version: 7.11.0
Library: resttemplate
OpenAPI declaration file content or url
I have used your petstore spec to reproduce the issue
Steps to reproduce
Run below command to generate the code
java -jar openapi-generator-cli-7.11.0.jar generate -i petstore.yaml -g java -o output --additional-properties=library=resttemplate
Go to the source files for ApiClient and UserApi, you'll see org.springframework.stereotype.Component being added by default
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component; <----- it should not be here
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
Suggest a fix
You just need to replace the current content in:
|
import org.springframework.stereotype.Component; |
|
import org.springframework.stereotype.Component; |
with below code
{{#generateClientAsBean}}
import org.springframework.stereotype.Component;
{{/generateClientAsBean}}
Bug Report Checklist
Description
The files generated from
resttemplateare importingorg.springframework.stereotype.Componenteven whengenerateClientAsBeanproperty is set tofalse(default).openapi-generator/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/api.mustache
Line 22 in dd67423
openapi-generator/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache
Line 31 in dd67423
According to the docs, the
@Componentannotation will be only added ifgenerateClientAsBeanis set totrueSo, to fix the issue, you just need to replace the current content with bellow suggestion in both places:
{{#generateClientAsBean}} import org.springframework.stereotype.Component; {{/generateClientAsBean}}openapi-generator version
I'm currently using below settings - however I can reproduce the issue in prior versions
OpenAPI declaration file content or url
I have used your
petstorespec to reproduce the issueSteps to reproduce
Run below command to generate the code
Go to the source files for
ApiClientandUserApi, you'll seeorg.springframework.stereotype.Componentbeing added by defaultSuggest a fix
You just need to replace the current content in:
openapi-generator/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/api.mustache
Line 22 in dd67423
openapi-generator/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache
Line 31 in dd67423
with below code
{{#generateClientAsBean}} import org.springframework.stereotype.Component; {{/generateClientAsBean}}