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

Duplicate GroupConfigs in SpringDocConfigProperties #2518

Closed
fkreis opened this issue Feb 29, 2024 · 2 comments
Closed

Duplicate GroupConfigs in SpringDocConfigProperties #2518

fkreis opened this issue Feb 29, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@fkreis
Copy link

fkreis commented Feb 29, 2024

Describe the bug
For my usecase I want to access the springdoc specific application.properties at Runtime. I thought it is a smart idea to reuse springdoc's exsiting SpringDocConfigProperties class which can be autowired. Using this class I have type safety and avoid re-reading all the springdoc properties from appliation.properties again.

However, SpringDocConfigProperties.getGroupConfigs() returns twice the size of the actual configured amount of groups (e.g. in my example I configured 4 groups, but 8 are returned). Each group gets duplicated.

To Reproduce
Steps to reproduce the behavior:

  • Spring boot 3.2.3
  • springdoc-openapi-starter-webmvc-ui:2.3.0
  • application.properties:
    springdoc.group-configs[0].group=Group0
    springdoc.group-configs[0].packages-to-scan=com.my-package
    springdoc.group-configs[1].group=Group1
    springdoc.group-configs[1].packages-to-scan=com.my-package
    springdoc.group-configs[2].group=Group2
    springdoc.group-configs[2].packages-to-scan=com.my-package
    springdoc.group-configs[3].group=Group3
    springdoc.group-configs[3].packages-to-scan=com.my-package
  • Application.java:
    @EnableScheduling
    @SpringBootApplication
    public class Application {
    
        @Autowired
        private  SpringDocConfigProperties springDocConfigProperties;
    
        public static void main(String[] args) {
            SpringApplication.run(Application.class, args);
        }
    
        @PostConstruct
        @Scheduled(fixedRate = 1000)
        public void printSize() {
            System.out.println(springDocConfigProperties.getGroupConfigs().stream().map(GroupConfig::getGroup).toList());
        }
    }
    

Expected behavior

  • Should print [Group0, Group1, Group2, Group3] every 1000ms
  • Actually it prints the expected text only once. Afterwards it starts printing [Group0, Group1, Group2, Group3, Group0, Group1, Group2, Group3]
  • Apparently, at some point after the start, all GroupConfigs get duplicated
@fkreis
Copy link
Author

fkreis commented Feb 29, 2024

It works as expected (I only get 4 groups) when I create the groups as GroupedOpenApi Beans instead of via application.properties:

@Bean
public GroupedOpenApi group0() {
    return GroupedOpenApi.builder()
            .group("Group0")
            .packagesToScan("com.myPackage")
            .build();
}

@bnasslahsen
Copy link
Contributor

@fkreis,

Thanks for the report.
Should be fixed with the latest SNAPSHOT.

@bnasslahsen bnasslahsen added the bug Something isn't working label Mar 2, 2024
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
Development

No branches or pull requests

2 participants