我在https://micronaut-projects.github.io/micronaut-openapi/latest/guide/上跟踪openapi的micronaut,并且UI没有生成,每次我试图访问/swagger时,/swagger-ui都会出现以下错误:
{
"message": "Not Found",
"_links": {
"self": {
"href": "/swagger",
"templated": false
}
},
"_embedded": {
"errors": [
{
"message": "Page Not Found"
}
]
}
}安装了依赖项:
implementation("io.swagger.core.v3:swagger-annotations")
annotationProcessor("io.micronaut.openapi:micronaut-openapi:4.5.2")application.yml上的路由器定义如下:
micronaut:
application:
name: myapp
router:
static-resources:
default:
enabled: true
swagger:
enabled: true
paths: classpath:META-INF/swagger
mapping: /swagger/**并创建根文件夹上的文件openapi.properties:
swagger-ui.enabled=true
micronaut.openapi.views.spec=apidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop
micronaut.openapi.expand.api.version=v0.1
micronaut.openapi.expand.openapi.description=myapp根据文档,应该生成一个.yml文件;
为Kotlin build/tmp/kapt3/classes/main/META-INF/swagger/myapp-0.1.yml
在我的控制器上,我也有Operation和ApiResponses注释,但是当我运行应用程序时,没有生成文件yml,我如何才能在micronaut项目上正确地启用swagger呢?
发布于 2022-10-22 09:03:37
您只在您的swagger中定义了application.yml。您还应该为swagger-ui添加一个具有类似定义的部分:
micronaut:
application:
name: openapitest
router:
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
swagger-ui:
paths: classpath:META-INF/swagger/views/swagger-ui
mapping: /swagger-ui/**另外,我使用了默认的openapi.properties文件:
swagger-ui.enabled=true
redoc.enabled=false
rapidoc.enabled=false
rapidoc.bg-color=#14191f
rapidoc.text-color=#aec2e0
rapidoc.sort-endpoints-by=method你试过用clean和build使用gradlew吗?
我在存储库上创建了一个示例GitHub,您可以检查它。
=========UPDATE========
好的,我发现什么是不正确的!您使用的是annotation-processing:
annotationProcessor("io.micronaut.openapi:micronaut-openapi:4.5.2")但是如果您使用的是Kotlin,则应该使用kapt - Kotlin注释处理工具。这里有几篇文章-- link1,link2。
因此,你应该改为:
kapt("io.micronaut.openapi:micronaut-openapi:4.5.2")https://stackoverflow.com/questions/74159094
复制相似问题