OpenAPITools / OpenAPITools/openapi-generator

[BUG] useFeignClientContextId default option causes IllegalStateException at runtime

Open
#21,521 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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.

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.

Research direction

Start by reviewing the useFeignClientContextId change in #20943 and reproduce the generated CountriesApiClient with Spring Cloud OpenFeign 4.3.0. Trace how the name and nested contextId expressions are produced, then add or update a regression test so the default configuration no longer causes the reported IllegalStateException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.