Skip to content

Commit

Permalink
Also ignore nested roots, when ignoring a path (#917)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Mar 31, 2023
1 parent f7d2012 commit 5ee9ca0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ final class ConfigMappingProvider implements Serializable {
}

static void ignoreRecursively(KeyMap<BiConsumer<ConfigMappingContext, NameIterator>> root) {
if (root.getRootValue() == null) {
root.putRootValue(DO_NOTHING);
}

if (root.getAny() == null) {
root.putAny(IGNORE_EVERYTHING);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1650,9 +1650,10 @@ void ignoreNestedUnknown() {
.withSources(config("ignore.nested.nested.value", "value", "ignore.nested.nested.ignore", "ignore"))
.withSources(config("ignore.nested.optional.value", "value", "ignore.nested.optional.ignore", "ignore"))
.withSources(config("ignore.nested.list[0].value", "value", "ignore.nested.list[0].ignore", "ignore"))
.withSources(config("ignore.nested.map.key", "value", "ignore.nested.map.ignored.ignored", "ignore"))
.withSources(config("ignore.nested.map.key.value", "value", "ignore.nested.map.ignored.ignored", "ignore"))
.withSources(config("ignore.nested.key.value", "parent", "ignore.nested.ignored.ignored", "ignore"))
.withSources(config("ignore.nested.ignore.ignore", "ignore"))
.withMappingIgnore("ignore.nested.**")
.withMappingIgnore("ignore.**")
.build();

IgnoreNestedUnknown mapping = config.getConfigMapping(IgnoreNestedUnknown.class);
Expand All @@ -1662,7 +1663,8 @@ void ignoreNestedUnknown() {
assertTrue(mapping.optional().isPresent());
assertEquals("value", mapping.optional().get().value());
assertEquals("value", mapping.list().get(0).value());
assertEquals("value", mapping.map().get("key"));
assertEquals("value", mapping.map().get("key").value());
assertEquals("parent", mapping.mapParent().get("key").value());
}

@ConfigMapping(prefix = "ignore.nested")
Expand All @@ -1675,7 +1677,10 @@ interface IgnoreNestedUnknown {

List<Nested> list();

Map<String, String> map();
Map<String, Nested> map();

@WithParentName
Map<String, Nested> mapParent();

interface Nested {
String value();
Expand Down

0 comments on commit 5ee9ca0

Please sign in to comment.