From 5e359a1db29811edd4c583ccdeb85595c86d256d Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Mon, 29 Jul 2024 22:22:01 +0100 Subject: [PATCH] Drop support for full YAML content in parent property names --- .../config/source/yaml/YamlConfigSource.java | 29 --------- .../source/yaml/YamlConfigSourceTest.java | 59 ------------------- 2 files changed, 88 deletions(-) diff --git a/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java b/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java index 19400f14b..4f017898f 100644 --- a/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java +++ b/sources/yaml/src/main/java/io/smallrye/config/source/yaml/YamlConfigSource.java @@ -8,10 +8,8 @@ import java.net.URL; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.TreeMap; import java.util.function.Function; import java.util.stream.Collectors; @@ -47,11 +45,8 @@ public class YamlConfigSource extends MapBackedConfigSource { DUMPER = new Yaml(dumperOptions); } - private final Set propertyNames; - public YamlConfigSource(String name, Map source, int ordinal) { super(name, source, ordinal, false); - this.propertyNames = filterPropertyNames(source); } public YamlConfigSource(URL url) throws IOException { @@ -77,11 +72,6 @@ public YamlConfigSource(String name, String source, int ordinal) { this(name, stringToMap(source), ordinal); } - @Override - public Set getPropertyNames() { - return propertyNames; - } - @SuppressWarnings("unchecked") private static Map streamToMap(InputStream inputStream) throws IOException { Assert.checkNotNullParam("inputStream", inputStream); @@ -181,12 +171,6 @@ private static void flattenList(String key, List source, Map filterPropertyNames(Map source) { - final Set filteredKeys = new HashSet<>(); - for (final String key : new HashSet<>(source.keySet())) { - if (key.startsWith(YamlConfigSource.class.getName() + ".filter.")) { - String originalKey = key.substring(55); - source.put(originalKey, source.remove(key)); - } else { - filteredKeys.add(key); - } - } - return filteredKeys; - } - /** * Override some yaml constructors, so that the value written in the flatten result is more alike with the * source. For instance, timestamps may be written in a completely different format which prevents converters to diff --git a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java index 7eccf8fe5..9c1a73d66 100644 --- a/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java +++ b/sources/yaml/src/test/java/io/smallrye/config/source/yaml/YamlConfigSourceTest.java @@ -26,34 +26,6 @@ import io.smallrye.config.SmallRyeConfigBuilder; class YamlConfigSourceTest { - @Test - void flatten() { - String yaml = "admin:\n" + - " users:\n" + - " -\n" + - " email: \"joe@gmail.com\"\n" + - " username: \"joe\"\n" + - " password: \"123456\"\n" + - " roles:\n" + - " - \"Moderator\"\n" + - " - \"Admin\"\n" + - " -\n" + - " email: \"jack@gmail.com\"\n" + - " username: \"jack\"\n" + - " password: \"654321\"\n" + - " roles:\n" + - " - \"Moderator\"\n"; - - YamlConfigSource source = new YamlConfigSource("yaml", yaml); - String value = source.getValue("admin.users"); - Users users = new UserConverter().convert(value); - assertEquals(2, users.getUsers().size()); - assertEquals(users.users.get(0).getEmail(), "joe@gmail.com"); - assertEquals(users.users.get(0).getRoles(), Stream.of("Moderator", "Admin").collect(toList())); - - assertEquals("joe@gmail.com", source.getValue("admin.users[0].email")); - } - @Test void profiles() { String yaml = "---\n" + @@ -149,37 +121,6 @@ void indentSpaces() { assertEquals("smallrye", config.getRawValue("greeting.name")); } - @Test - void config() { - String yaml = "admin:\n" + - " users:\n" + - " -\n" + - " email: \"joe@gmail.com\"\n" + - " username: \"joe\"\n" + - " password: \"123456\"\n" + - " roles:\n" + - " - \"Moderator\"\n" + - " - \"Admin\"\n" + - " -\n" + - " email: \"jack@gmail.com\"\n" + - " username: \"jack\"\n" + - " password: \"654321\"\n" + - " roles:\n" + - " - \"Moderator\"\n"; - - SmallRyeConfig config = new SmallRyeConfigBuilder() - .withSources(new YamlConfigSource("yaml", yaml)) - .withConverter(Users.class, 100, new UserConverter()) - .build(); - - Users users = config.getValue("admin.users", Users.class); - assertEquals(2, users.getUsers().size()); - assertEquals(users.users.get(0).getEmail(), "joe@gmail.com"); - assertEquals(users.users.get(0).getRoles(), Stream.of("Moderator", "Admin").collect(toList())); - - assertEquals("joe@gmail.com", config.getRawValue("admin.users[0].email")); - } - @Test void propertyNames() { String yaml = "quarkus:\n" +