swagger-api / swagger-api/swagger-codegen

[SpringCloud/OpenFeign] Support is broken out of the box

Open
#10,343 3 comments 5 reactions 1 assignee View on GitHub

@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
  1. OpenFeign does not override default methods.
  2. The default behaviour with <library>spring-cloud</library> is to generate default methods.
  3. Even when manually forcing defaultInterfaces=false, if you have java8=true, there is still left over crud from the defaultInterfaces support.
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
  1. defaultInterfaces=true should be the default when <library>spring-cloud</library> is used.
  2. Fix api.mustache to not include the following when using <library>spring-cloud</library>
    Logger log = LoggerFactory.getLogger(AccountBalancesApi.class);

    Optional<ObjectMapper> getObjectMapper();

    Optional<HttpServletRequest> getRequest();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.