-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The files generated from resttemplate are importing org.springframework.stereotype.Component even when generateClientAsBean property is set to false (default).
Line 22 in dd67423
import org.springframework.stereotype.Component; Line 31 in dd67423
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:
Line 22 in dd67423
import org.springframework.stereotype.Component; Line 31 in dd67423
import org.springframework.stereotype.Component;
with below code
{{#generateClientAsBean}}
import org.springframework.stereotype.Component;
{{/generateClientAsBean}}