如何通过代码设置OpenAPI配置,而不是在Micronaut中使用注释

发布于 2025-02-13 17:04:18 字数 1174 浏览 2 评论 0原文

我有一个Springboot应用程序,我想转换为Micronaut,但是我如何通过代码配置OpenAPI,例如本文

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

代码tippet:
@配置 公共类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/");
}

}

当前,我已经完成了FF:

  1. 替换@bean as @singleton,失败了,
  2. 将@factory添加到类中,失败了
    **应用程序编译,但是在运行时,OpenAPI定义未设置在Swagger UI上

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落日海湾 2025-02-20 17:04:18

Micronaut在编译时生成开放式API定义,因此不可能具有动态属性。唯一的方法是设置这些值是使用注释 https://micronaut-projects.github.io/micronaut-openapi/latest/guide/guide/index.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文