openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] useFeignClientContextId default option causes IllegalStateException at runtime

Open moreginger opened this issue 6 months ago • 4 comments

Bug Report Checklist

  • [ ] Have you provided a full/minimal spec to reproduce the issue?
  • [ ] Have you validated the input using an OpenAPI validator?
  • [ ] Have you tested with the latest master to confirm the issue still exists?
  • [ ] Have you searched for related issues/PRs?
  • [ ] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Following the introduction of useFeignCleintContextId with default true in #20943, the contextId by default fails to resolve a valid service name and throws an exception, e.g.:

Service id not legal hostname (${countries.name})
java.lang.IllegalStateException: Service id not legal hostname (${countries.name})
	at org.springframework.util.Assert.state(Assert.java:79)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.getName(FeignClientsRegistrar.java:111)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.getContextId(FeignClientsRegistrar.java:346)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.eagerlyRegisterFeignClientBeanDefinition(FeignClientsRegistrar.java:230)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerFeignClient(FeignClientsRegistrar.java:215)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerFeignClients(FeignClientsRegistrar.java:204)
	at org.springframework.cloud.openfeign.FeignClientsRegistrar.registerBeanDefinitions(FeignClientsRegistrar.java:154)
	at org.springframework.context.annotation.ImportBeanDefinitionRegistrar.registerBeanDefinitions(ImportBeanDefinitionRegistrar.java:86)

This is with org.springframework.cloud:spring-cloud-starter-openfeign:4.3.0

The generated feign client looks like this:

@FeignClient(name="${countries.name:countries}", contextId="${countries.contextId:${countries.name}}",  configuration = ClientConfiguration.class)
public interface CountriesApiClient extends CountriesApi {
}
openapi-generator version

7.13.0

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs

#20943

Suggest a fix

Is it possible for the contextId to actually resolve the nested countries.name expression or is it doomed to fail? In any case, I think it would be better to default this new option to false rather than true.

moreginger avatar Jul 04 '25 10:07 moreginger

thanks for reporting the issue

cc @paveliam, the author of the PR

wing328 avatar Jul 05 '25 08:07 wing328

I am also forced to set back the version to v7.11.0 to make our services running.

maxl2287 avatar Jul 09 '25 07:07 maxl2287

Maybe related feature should at least be labeled as "Breaking Change"?

AlexanderInozemtsev avatar Dec 02 '25 12:12 AlexanderInozemtsev

I just disabled right now the contextId usage, by configuring:

<useFeignClientContextId>false</useFeignClientContextId>

maxl2287 avatar Dec 02 '25 12:12 maxl2287