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

Nested of Optionals and Maps is broken when YAMLSource is used #762

Closed
gastaldi opened this issue Jun 9, 2022 · 0 comments · Fixed by #766
Closed

Nested of Optionals and Maps is broken when YAMLSource is used #762

gastaldi opened this issue Jun 9, 2022 · 0 comments · Fixed by #766
Labels
bug Something isn't working

Comments

@gastaldi
Copy link
Contributor

gastaldi commented Jun 9, 2022

Original issue: quarkusio/quarkus#26009

Having a ConfigMapping like:

@ConfigMapping(prefix = "message-util-configurations", namingStrategy = ConfigMapping.NamingStrategy.KEBAB_CASE)
public interface MessageUtilConfigurations {
    Optional<Boolean> enableDataswapDetection();

    Map<String, Map<String, MessageUtilConfiguration>> messageUtilConfigsMap();

    interface MessageUtilConfiguration {
        Optional<Boolean> enableDataswapDetection();
    }

}

And an YAML like:

message-util-configurations:
  enable-dataswap-detection: true
  message-util-configs-map:
    filter:
      default:
        enable-dataswap-detection: false
      get-jokes-uni:
        enable-dataswap-detection: true
    client:
      reaction-api:
        enable-dataswap-detection: true
      setup-api:
        enable-dataswap-detection: true

The following test fails:

    @Test
    void testNestingConfig() throws Exception {
        SmallRyeConfig config = new SmallRyeConfigBuilder()
                .withSources(new YamlConfigSource(
                        getClass().getClassLoader().getResource("example-nesting.yml")))
                .withMapping(MessageUtilConfigurations.class)
                .build();
        MessageUtilConfigurations root = config.getConfigMapping(MessageUtilConfigurations.class);
        assertEquals(2, root.messageUtilConfigsMap().keySet().size());
    }

PS: The bug was introduced by this commit

Here is the full Test case for reference purposes:

package io.smallrye.config.source.yaml;

import io.smallrye.config.ConfigMapping;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Map;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class YamlConfigNestingTest {

    @Test
    void testNestingConfig() throws Exception {
        SmallRyeConfig config = new SmallRyeConfigBuilder()
                .withSources(new YamlConfigSource(
                        getClass().getClassLoader().getResource("example-nesting.yml")))
                .withMapping(MessageUtilConfigurations.class)
                .build();
        MessageUtilConfigurations root = config.getConfigMapping(MessageUtilConfigurations.class);
         
        assertEquals(2, root.messageUtilConfigsMap().keySet().size(), "Should have returned 'filter' and 'client'");
    }

    @ConfigMapping(prefix = "message-util-configurations", namingStrategy = ConfigMapping.NamingStrategy.KEBAB_CASE)
    public interface MessageUtilConfigurations {
        Optional<Boolean> enableDataswapDetection();

        Map<String, Map<String, MessageUtilConfiguration>> messageUtilConfigsMap();

        interface MessageUtilConfiguration {
            Optional<Boolean> enableDataswapDetection();
        }

    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants