Skip to content

Commit

Permalink
Do not override defaults namespace in the DefaultValuesConfigSource
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Sep 1, 2022
1 parent c362ff4 commit 8e8580a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.smallrye.config;

import java.util.Map;

public class DefaultValuesConfigSource extends KeyMapBackedConfigSource {
private static final long serialVersionUID = -6386021034957868328L;

Expand All @@ -10,8 +8,6 @@ public DefaultValuesConfigSource(final KeyMap<String> properties) {
}

void registerDefaults(final KeyMap<String> properties) {
for (Map.Entry<String, KeyMap<String>> entry : properties.entrySet()) {
getKeyMapProperties().put(entry.getKey(), entry.getValue());
}
getKeyMapProperties().putAll(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1553,4 +1553,32 @@ void optionalExpressions() {
assertFalse(mapping.expression().isPresent());
assertFalse(mapping.expressionInt().isPresent());
}

@Test
void defaultsBuilderAndMapping() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.addDefaultInterceptors()
.withMapping(DefaultsBuilderAndMapping.class)
.withDefaultValue("server.host", "localhost")
.build();

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

assertEquals("localhost", config.getRawValue("server.host"));
assertEquals(443, mapping.ssl().port());
assertEquals(2, mapping.ssl().protocols().size());
}

@ConfigMapping(prefix = "server")
interface DefaultsBuilderAndMapping {
Ssl ssl();

interface Ssl {
@WithDefault("443")
int port();

@WithDefault("TLSv1.3,TLSv1.2")
List<String> protocols();
}
}
}

0 comments on commit 8e8580a

Please sign in to comment.