swagger-api / swagger-api/swagger-codegen
[SpringCloud/OpenFeign] Support is broken out of the box
Open
@gracekarina is already working on this.
Since Jun 24, 2020.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
- OpenFeign does not override
defaultmethods. - The default behaviour with
<library>spring-cloud</library>is to generatedefaultmethods. - Even when manually forcing
defaultInterfaces=false, if you havejava8=true, there is still left over crud from thedefaultInterfacessupport.
Swagger-codegen version
swagger-codegen-maven-plugin/3.0.20
Steps to reproduce
Note: other standard configuration options have been omitted..
<configuration>
<language>spring</language>
<library>spring-cloud</library>
<configOptions>
<java8>true</java8>
<defaultInterfaces>false</defaultInterfaces>
<generateForOpenFeign>true</generateForOpenFeign>
</configOptions>
</configuration>
results in the generated code:
Logger log = LoggerFactory.getLogger(AccountBalancesApi.class);
Optional<ObjectMapper> getObjectMapper();
Optional<HttpServletRequest> getRequest();
being added to every API class.
Which fails when trying to load the API via OpenFeign...
Caused by: java.lang.IllegalStateException: Method getObjectMapper not annotated with HTTP method type (ex. GET, POST)
at feign.Util.checkState(Util.java:130) ~[feign-core-10.4.0.jar:na]
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:99) ~[feign-core-10.4.0.jar:na]
at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:188) ~[spring-cloud-openfeign-core-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:66) ~[feign-core-10.4.0.jar:na]
at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:154) ~[feign-core-10.4.0.jar:na]
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:52) ~[feign-core-10.4.0.jar:na]
at feign.Feign$Builder.target(Feign.java:251) ~[feign-core-10.4.0.jar:na]
Suggest a fix/enhancement
defaultInterfaces=trueshould be the default when<library>spring-cloud</library>is used.- Fix
api.mustacheto not include the following when using<library>spring-cloud</library>
Logger log = LoggerFactory.getLogger(AccountBalancesApi.class);
Optional<ObjectMapper> getObjectMapper();
Optional<HttpServletRequest> getRequest();
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.
Assessment
This issue has not been assessed yet.