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

Quarkus @ConfigMapping does not read the properties supplied for the profile #45077

Open
praiaAndrewLeach opened this issue Dec 12, 2024 · 1 comment
Labels

Comments

@praiaAndrewLeach
Copy link

Describe the bug

Our team supports a simple service that exposes a handful of APIs. For the purposes of fast iteration, we're loading all of our "data" into a config entry in our application.yaml.

The structure of the YAML looks like this (data anonymized, but it resembles the actual structure)

app:
 service:
    mock-data:
      components:
        home:
          - name: MyComponent
          - name: YourComponent
          - name: OurComponent
    enabled: true  
"%test":
    app:
        service:
          mock-data:
            components:
              home:
                - name: TestComponent
          enabled: true

There is also an instance of a @ConfigMapping object that looks like this:

@ConfigMapping(prefix = "app")
public interface AppConfigMapping {
    Service service();

    interface Service {
        boolean enabled();

        MockData mockData();
    }

    interface MockData {
        Map<String, List<Component>> components();
    }

    interface Component {
        String name();
    }
}

The main issue is that Quarkus will load into the "home" entry whichever array is greater. It does not respect the property set for that specific profile.

Test

package com.mypackage;

import static org.assertj.core.api.Assertions.assertThat;

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

import jakarta.inject.Inject;

import io.quarkus.test.junit.QuarkusTest;

import org.junit.jupiter.api.Test;

@QuarkusTest
public class AppConfigMappingTest {
    @Inject
    AppConfigMapping appConfigMapping;

    @Test
    public void isMockDataShapedCorrectly() {
        Map<String, List<AppConfigMapping.Component>> components =
                appConfigMapping.service().mockData().components();
        assertThat(components).isNotNull();
        assertThat(components.get("home")).isNotEmpty().hasSize(1); // Fails, size of the array is 3
    }
}

For example, when we ran this test against these config entries, the home key, consistently returned:

- name: MyComponent
- name: YourComponent
- name: OurComponent  

Expected behavior

The expected behavior is that when we run the same test in the description, the key "home" should return a list of 1 element consisting of this value:

- name: TestComponent

Actual behavior

The actual behavior is that when we run the same test in the description, the key "home" returns a list of 3 elements consisting of these values:

- name: MyComponent
- name: YourComponent
- name: OurComponent  

How to Reproduce?

Reproducer: config-mapping-bug.zip

Steps to reproduce:

  1. Run quarkus test

Output of uname -a or ver

Darwin MacBook-Pro.local 24.1.0 Darwin Kernel Version 24.1.0: Thu Oct 10 21:00:32 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T6030 arm64

Output of java -version

openjdk 21 2023-09-19 LTS OpenJDK Runtime Environment Temurin-21+35 (build 21+35-LTS) OpenJDK 64-Bit Server VM Temurin-21+35 (build 21+35-LTS, mixed mode)

Quarkus version or git rev

3.17.4

Build tool (ie. output of mvnw --version or gradlew --version)

------------------------------------------------------------ Gradle 8.8 ------------------------------------------------------------ Build time: 2024-05-31 21:46:56 UTC Revision: 4bd1b3d3fc3f31db5a26eecb416a165b8cc36082 Kotlin: 1.9.22 Groovy: 3.0.21 Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023 JVM: 21 (Eclipse Adoptium 21+35-LTS) OS: Mac OS X 15.1.1 aarch64

Additional information

No response

@praiaAndrewLeach praiaAndrewLeach added the kind/bug Something isn't working label Dec 12, 2024
Copy link

quarkus-bot bot commented Dec 12, 2024

/cc @geoand (kotlin), @radcortez (config)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant