Skip to content

Commit

Permalink
Do not remove dotted property names from EnvSource when matching Conf…
Browse files Browse the repository at this point in the history
…igMapping patterns (smallrye#1050)
  • Loading branch information
radcortez authored Nov 9, 2023
1 parent 9b38df0 commit ffcad09
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
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

0 comments on commit ffcad09

Please sign in to comment.