[REQ][Java][Spring][Feign] Support for specifying Feign fallback and fallbackFactory in spring-cloud client generation
Is your feature request related to a problem? Please describe.
I'm using the spring generator with the library option set to spring-cloud to generate Feign clients. While the generated clients support specifying a configuration class, they do not currently support setting fallback or fallbackFactory.
This limitation makes it difficult to apply fallback logic, which is essential for resilience in production environments. Although many customizations can be handled via configuration classes or application.properties, fallback behavior seems to be an exception.
Describe the solution you'd like
It would be helpful if the generator could support specifying fallback and/or fallbackFactory for Feign clients in the generated code. Ideally, this could be handled via generator options or annotations, allowing users to plug in their custom fallback implementations easily.
Describe alternatives you've considered
Currently, I need to manually modify the generated code to set the fallback or fallbackFactory, which undermines the purpose of code generation. Other workarounds, such as programmatically wrapping the client, are more complex and not ideal.
Additional context
Feign provides a very convenient client abstraction, and when using OpenAPI + Java + Spring, it is a strong candidate for client generation. However, the lack of fallback support in the generated code is a blocker for production usage in many cases where resilience is critical.
There was also a similar request made in the past here: https://github.com/OpenAPITools/openapi-generator/issues/1396
Sorry, I forgot to mention this earlier. The official Spring documentation for fallback and fallbackFactory in Spring Cloud OpenFeign is available here: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/#spring-cloud-feign-circuitbreaker-fallback
I want this feature also.
I want this feature also.
hi, i recently learn, spring boot recommended http interface not OpenFeign. i adopted http interface.
see: https://docs.spring.io/spring-framework/reference/integration/rest-clients.html#rest-http-service-client
i think, i should closing this issue. i close.
Thank you so much for letting me know the HTTP Interface. I will study it.
@takashno
I studied a bit the Spring HTTP Interface. It is a very good tool that provides the similar simplicity the OpenFeign does and at the same time the flexibility to choose the underlying implementation from like the RestTemplate and the reactive WebClient where the OpenFeign does not provide. One small shortcoming is the integration with the Resilience4J Circuit Breaker is not as "native" as what OpenFeign does, but it is not a big deal as we can add CircuitBreaker annotations to the client interface simply to achieve this, which is the official approach to use circuit breakers. I guess I will switch to use HTTP Interface for new projects.
But still I think the fallback/fallbackFactory support for OpenFeign in OpenAPI Generator has its own value. OpenFeign is one type of clients that OpenAPI Generator officially supports. For those projects that have already adopted OpenFeign and OpenAPI Generator the missing of the support is a blocker if they want to add resilience. Although it still can be done by like writing a wrapper class with CircuitBreaker annotations, it is not a "native" approach for OpenFeign, it is more like a workaround. That said, OpenFeign's power is not fully utilized in a native way when work together with OpenAPI Generator. I guess it will not be complex to add such support. I will try to look into this how it can be implemented.
What do you think?
(BTW, the HTTP Interface support has an open bug for long time issue#19712)