如何通过代码设置OpenAPI配置,而不是在Micronaut中使用注释
我有一个Springboot应用程序,我想转换为Micronaut,但是我如何通过代码配置OpenAPI,例如本文
代码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:
- 替换@bean as @singleton,失败了,
- 将@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
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:
- Replace @Bean as @Singleton, Failed
- Adding @Factory to the class, Failed
** The application compiles, but on run time the OpenApi definition is not set on the swagger ui
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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