OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java][Spring] Feign Clients have the same name when multiple tags are specified
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Spring generator using the spring-cloud library generates a Feign client for each tag used in the API specification.
However the name on each client is the same, causing an Invalid bean definition with name error on startup, due to the duplicate name.
Settings:
<configOptions>
<sourceFolder>${generated-sources-java-path}</sourceFolder>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<library>spring-cloud</library>
<useBeanValidation>true</useBeanValidation>
<performBeanValidation>true</performBeanValidation>
</configOptions>
<generatorName>spring</generatorName>
Example code generated:
@FeignClient(name="${springMicroservice.name:springMicroservice}", url="${springMicroservice.url:http://localhost}", configuration = ClientConfiguration.class)
public interface TagOneApiClient extends TagOneApi {
}
@FeignClient(name="${springMicroservice.name:springMicroservice}", url="${springMicroservice.url:http://localhost}", configuration = ClientConfiguration.class)
public interface TagTwoApiClient extends TagTwoApi {
}
Example error:
Caused by: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name '${springMicroservice.name:springMicroservice}.FeignClientSpecification' defined in null: Cannot register bean definition [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean '${springMicroservice.name:springMicroservice}.FeignClientSpecification': There is already [Generic bean: class [org.springframework.cloud.openfeign.FeignClientSpecification]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
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.
Research direction
Start at the Spring generator's spring-cloud path and trace how the FeignClient annotation is produced for APIs created from multiple tags. Compare the generated annotations for TagOneApiClient and TagTwoApiClient, then identify an existing generator test area for this output. Done means separately generated clients no longer register the same Feign client name and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100