Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not remove dotted property names from EnvSource when matching ConfigMapping patterns #1050

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,11 @@ private static void matchPropertiesWithEnv(final SmallRyeConfig config, final Se
for (Integer dash : indexOfDashes) {
sb.setCharAt(dash, '-');
}
envConfigSource.getPropertyNames().add(sb.toString());
envConfigSource.getPropertyNames().remove(envProperty);
String expectedEnvProperty = sb.toString();
if (!envProperty.equals(expectedEnvProperty)) {
envConfigSource.getPropertyNames().add(sb.toString());
envConfigSource.getPropertyNames().remove(envProperty);
}
sb.setLength(0);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,48 @@ void sameNames() {
assertEquals("upper", envConfigSource.getValue("MY_STRING_PROPERTY"));
}

@Test
void dashedEnvNames() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withMapping(DashedEnvNames.class)
.withSources(new EnvConfigSource(Map.of(
"DASHED_ENV_NAMES_VALUE", "value",
"DASHED_ENV_NAMES_NESTED__DASHED_KEY__ANOTHER", "value"), 100))
.build();

DashedEnvNames mapping = config.getConfigMapping(DashedEnvNames.class);

assertEquals("value", mapping.value());
// Unfortunately, we still don't have a good way to determine if the Map key is dashed or not
assertEquals("value", mapping.nested().get("dashed.key").another());
}

@Test
void dottedDashedEnvNames() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withMapping(DashedEnvNames.class)
.withSources(new EnvConfigSource(Map.of(
"dashed-env-names.value", "value",
"dashed-env-names.nested.dashed-key.another", "value"), 100))
.build();

DashedEnvNames mapping = config.getConfigMapping(DashedEnvNames.class);

assertEquals("value", mapping.value());
assertEquals("value", mapping.nested().get("dashed-key").another());
}

@ConfigMapping(prefix = "dashed-env-names")
interface DashedEnvNames {
String value();

Map<String, Nested> nested();

interface Nested {
String another();
}
}

private static boolean envSourceEquals(String name, String lookup) {
return BOOLEAN_CONVERTER.convert(new EnvConfigSource(Map.of(name, "true"), 100).getValue(lookup));
}
Expand Down
Loading