OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.74k stars 6.32k forks source link

[Spring-Cloud] Add fallback at Feign Client #1396

Open developerpat opened 5 years ago

developerpat commented 5 years ago
Description

We have the following Situation: We generate a Feign Client with the OpenAPI-Generator. This produces following Code:

import org.springframework.cloud.openfeign.FeignClient;
import org.openapitools.configuration.ClientConfiguration;

@FeignClient(name="${test.name:test}", url="${test.url:https://test/abc/v1}", configuration = ClientConfiguration.class)
public interface ApiClient extends Api {
}

In the Feign client it is possible to set a fallback class which is executed when the external System is not reachable. This would look like this:

import org.springframework.cloud.openfeign.FeignClient;
import org.openapitools.configuration.ClientConfiguration;

@FeignClient(name="${test.name:test}", url="${test.url:https://test/abc/v1}", configuration = ClientConfiguration.class, fallback = TestFallback.class)
public interface ApiClient extends Api {
}

I couldn't find any configuration to set the fallback class.

openapi-generator version
<version>3.3.1</version>
OpenAPI declaration file content or url

/

Command line used for generation

/

Steps to reproduce

/

Related issues/PRs

/

Suggest a fix/enhancement

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/JavaSpring/libraries/spring-cloud/apiClient.mustache

Please add ",fallback = ClientFallback.class" to the FeignClient annotation and "import {{fallback.package}}.ClientFallback".

developerpat commented 5 years ago
package {{fallbackPackage}};

import org.springframework.stereotype.Component;
import {{package}}.{{classname}}Client;

@Component
public abstract class ClientFallback implements {{classname}}Client{

}

{{classname}} and {{package}} are empty in a supportfile. Can anybody help with this Problem?