Skip to content

Commit 27f6431

Browse files
committed
Do not fallback @RegisterRestClient#configKey if it matches the Rest Client class name
1 parent c825cfb commit 27f6431

File tree

3 files changed

+101
-15
lines changed

3 files changed

+101
-15
lines changed

extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/AbstractRestClientConfigBuilder.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,31 @@ public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder)
7474
quarkusFallbacks.put(restClient.getSimpleName(), quotedSimpleName);
7575
relocates.put(quotedSimpleName, quotedFullName);
7676

77-
if (restClient.getConfigKey() != null) {
78-
String quotedConfigKey = "\"" + restClient.getConfigKey() + "\"";
79-
if (restClient.isConfigKeyComposed()) {
80-
// Quoted Simple Name -> Quoted Config Key
81-
quarkusFallbacks.put(quotedSimpleName, quotedConfigKey);
82-
relocates.put(quotedConfigKey, quotedFullName);
83-
} else {
84-
// Quoted Simple Name -> Config Key
85-
quarkusFallbacks.put(quotedSimpleName, restClient.getConfigKey());
86-
relocates.put(restClient.getConfigKey(), quotedFullName);
87-
// Config Key -> Quoted Config Key
88-
quarkusFallbacks.put(restClient.getConfigKey(), quotedConfigKey);
89-
relocates.put(quotedConfigKey, quotedFullName);
77+
String configKey = restClient.getConfigKey();
78+
if (configKey != null && !restClient.isConfigKeyEqualsNames()) {
79+
String quotedConfigKey = "\"" + configKey + "\"";
80+
if (!quotedConfigKey.equals(quotedFullName) && !quotedConfigKey.equals(quotedSimpleName)) {
81+
if (restClient.isConfigKeyComposed()) {
82+
// Quoted Simple Name -> Quoted Config Key
83+
quarkusFallbacks.put(quotedSimpleName, quotedConfigKey);
84+
relocates.put(quotedConfigKey, quotedFullName);
85+
} else {
86+
// Quoted Simple Name -> Config Key
87+
quarkusFallbacks.put(quotedSimpleName, configKey);
88+
relocates.put(configKey, quotedFullName);
89+
// Config Key -> Quoted Config Key
90+
quarkusFallbacks.put(configKey, quotedConfigKey);
91+
relocates.put(quotedConfigKey, quotedFullName);
92+
}
9093
}
9194
}
9295

9396
// FQN -> FQN/mp-rest
9497
String mpRestFullName = restClient.getFullName() + "/mp-rest/";
9598
microProfileFallbacks.put(quotedFullName, mpRestFullName);
9699
relocates.put(mpRestFullName, quotedFullName);
97-
if (restClient.getConfigKey() != null) {
98-
String mpConfigKey = restClient.getConfigKey() + "/mp-rest/";
100+
if (configKey != null && !restClient.isConfigKeyEqualsNames()) {
101+
String mpConfigKey = configKey + "/mp-rest/";
99102
microProfileFallbacks.put(mpRestFullName, mpConfigKey);
100103
relocates.put(mpConfigKey, quotedFullName);
101104
}

extensions/resteasy-classic/rest-client-config/runtime/src/main/java/io/quarkus/restclient/config/RegisteredRestClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public String getConfigKey() {
3535
return configKey;
3636
}
3737

38+
public boolean isConfigKeyEqualsNames() {
39+
if (configKey == null) {
40+
return false;
41+
}
42+
43+
return configKey.equals(fullName) || configKey.equals(simpleName);
44+
}
45+
3846
public boolean isConfigKeyComposed() {
3947
if (configKey == null) {
4048
throw new IllegalStateException("configKey is null");

extensions/resteasy-classic/rest-client-config/runtime/src/test/java/io/quarkus/restclient/config/RestClientConfigTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.assertj.core.api.Assertions.assertThat;
44
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
56
import static org.junit.jupiter.api.Assertions.assertTrue;
67

78
import java.math.BigInteger;
@@ -67,6 +68,43 @@ public List<RegisteredRestClient> getRestClients() {
6768
verifyConfig(restClientsConfig.getClient(ConfigKeyRestClient.class));
6869
}
6970

71+
@Test
72+
void restClientConfigKeyMatchName() {
73+
SmallRyeConfig config = ConfigUtils.emptyConfigBuilder()
74+
.withMapping(RestClientsConfig.class)
75+
.withCustomizers(new SmallRyeConfigBuilderCustomizer() {
76+
@Override
77+
public void configBuilder(final SmallRyeConfigBuilder builder) {
78+
new AbstractRestClientConfigBuilder() {
79+
@Override
80+
public List<RegisteredRestClient> getRestClients() {
81+
return List.of(new RegisteredRestClient(ConfigKeyRestClient.class,
82+
ConfigKeyRestClient.class.getName()));
83+
}
84+
}.configBuilder(builder);
85+
}
86+
})
87+
.build();
88+
assertNotNull(config);
89+
90+
config = ConfigUtils.emptyConfigBuilder()
91+
.withMapping(RestClientsConfig.class)
92+
.withCustomizers(new SmallRyeConfigBuilderCustomizer() {
93+
@Override
94+
public void configBuilder(final SmallRyeConfigBuilder builder) {
95+
new AbstractRestClientConfigBuilder() {
96+
@Override
97+
public List<RegisteredRestClient> getRestClients() {
98+
return List.of(new RegisteredRestClient(ConfigKeyRestClient.class,
99+
ConfigKeyRestClient.class.getSimpleName()));
100+
}
101+
}.configBuilder(builder);
102+
}
103+
})
104+
.build();
105+
assertNotNull(config);
106+
}
107+
70108
@Test
71109
void restClientMicroProfile() {
72110
RegisteredRestClient registeredRestClient = new RegisteredRestClient(MPRestClient.class, null);
@@ -149,6 +187,43 @@ public List<RegisteredRestClient> getRestClients() {
149187
assertThat(clientConfig.queryParamStyle().get()).isEqualTo(QueryParamStyle.COMMA_SEPARATED);
150188
}
151189

190+
@Test
191+
void restClientMicroProfileConfigKeyMatchName() {
192+
SmallRyeConfig config = ConfigUtils.emptyConfigBuilder()
193+
.withMapping(RestClientsConfig.class)
194+
.withCustomizers(new SmallRyeConfigBuilderCustomizer() {
195+
@Override
196+
public void configBuilder(final SmallRyeConfigBuilder builder) {
197+
new AbstractRestClientConfigBuilder() {
198+
@Override
199+
public List<RegisteredRestClient> getRestClients() {
200+
return List.of(new RegisteredRestClient(MPConfigKeyRestClient.class,
201+
MPConfigKeyRestClient.class.getName()));
202+
}
203+
}.configBuilder(builder);
204+
}
205+
})
206+
.build();
207+
assertNotNull(config);
208+
209+
config = ConfigUtils.emptyConfigBuilder()
210+
.withMapping(RestClientsConfig.class)
211+
.withCustomizers(new SmallRyeConfigBuilderCustomizer() {
212+
@Override
213+
public void configBuilder(final SmallRyeConfigBuilder builder) {
214+
new AbstractRestClientConfigBuilder() {
215+
@Override
216+
public List<RegisteredRestClient> getRestClients() {
217+
return List.of(new RegisteredRestClient(MPConfigKeyRestClient.class,
218+
MPConfigKeyRestClient.class.getSimpleName()));
219+
}
220+
}.configBuilder(builder);
221+
}
222+
})
223+
.build();
224+
assertNotNull(config);
225+
}
226+
152227
private void verifyConfig(RestClientConfig config) {
153228
assertTrue(config.url().isPresent());
154229
assertThat(config.url().get()).isEqualTo("http://localhost:8080");

0 commit comments

Comments
 (0)