1

I have a springboot application and I want to convert to Micronaut, but how I config the openapi via code, like in this article

https://keepgrowing.in/java/springboot/how-to-secure-spring-boot-swagger-ui-with-basic-authentication/

Code snippet:
@Configuration public class OpenApiConfig {

@Bean
public OpenAPI customOpenAPI(OpenApiProperties properties) {
    var openApi = new OpenAPI()
            .info(getInfo(properties));

    return openApi;
}

private Info getInfo(OpenApiProperties properties) {
    return new Info()
            .title(properties.getProjectTitle())
            .description(properties.getProjectDescription())
            .version(properties.getProjectVersion())
            .license(getLicense());
}

private License getLicense() {
    return new License()
            .name("Unlicense")
            .url("https://unlicense.org/");
}

}

Currently, I have already done the ff:

  1. Replace @Bean as @Singleton, Failed
  2. Adding @Factory to the class, Failed
    ** The application compiles, but on run time the OpenApi definition is not set on the swagger ui

1 Answers1

1

Micronaut generates the Open-API definition at the compilation time, so it's not possible to have dynamic properties. The only way is to set those values is to use annotations https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html

Denis
  • 603
  • 4
  • 8