[BUG][SPRING] delegateController: The annotation @Autowired is disallowed for this location
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 64/100
Research direction
Inspect modules/openapi-generator/src/main/resources/JavaSpring/apiController.mustache around the referenced line and compare the generated controller for delegatePattern with library spring-mvc. Generate the pet.yml sample using the shown configuration, then compile the generated Java code. Done means the controller no longer produces the reported @Autowired location error.
Written by the indexing model from the issue text.
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)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
When using delegatePattern for spring-mvc configuration :
<configOptions>
<delegatePattern>true</delegatePattern>
<library>spring-mvc</library>
</configOptions>
In the controller, we have :
private final ElementsApiDelegate delegate;
public ElementsApiController(@org.springframework.beans.factory.annotation.Autowired(required = false) ElementsApiDelegate delegate) {
this.delegate = Optional.ofNullable(delegate).orElse(new ElementsApiDelegate() {});
}
And there is a Java compilation failure:
The annotation @Autowired is disallowed for this location.
openapi-generator version
4.1.3 and it's not a regression
OpenAPI declaration file content or url
https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/samples/yaml/pet.yml
Command line used for generation
<configuration>
...
<configOptions>
<delegatePattern>true</delegatePattern>
<library>spring-mvc</library>
</configOptions>
<library>spring-mvc</library>
</configuration>
Steps to reproduce
1/ run with any swagger openAPI or not
2/ configure delegatePattern + spring-mvc
3/ generate code for JAVA Spring
4/ have a look to the controller, there is a Java compilation failure
The annotation @Autowired is disallowed for this location
Related issues/PRs
#92 @cbornet
Suggest a fix
@org.springframework.beans.factory.annotation.Autowired(required = false) private final {{classname}}Delegate delegate;
public {{classname}}Controller({{classname}}Delegate delegate) {
{{#jdk8}}
this.delegate = Optional.ofNullable(delegate).orElse(new {{classname}}Delegate() {});
}
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 103
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from OpenAPITools/openapi-generator
-
Issue: Bug
Difficulty 1/5 Under an hour Newbie friendliness 91/100
OpenAPITools/openapi-generator#24978 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenAPITools/openapi-generator#24975 ·
-
Issue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenAPITools/openapi-generator#24859 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
OpenAPITools/openapi-generator#24852 · 1 comment ·
-
[BUG][KOTLIN] Fails to compile after updating to 7.25.0 with useJackson3=false useSpringBoot4=true OpenIssue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
OpenAPITools/openapi-generator#24842 · 1 comment ·
All issues in OpenAPITools/openapi-generator
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100