按照这里的文档 - https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html
我将 build.gradle 配置为包含用于 swagger yaml 生成的编译时任务,如下所示 -
tasks.withType(JavaCompile){
options.fork = true
options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop'
options.encoding = "UTF-8"
options.compilerArgs.add('-parameters')}
这就是我的 application.yaml 的样子——
micronaut:
application:
name: email-api
server:
port: 5655
cors:
enabled: true
security:
enabled: true
token:
jwt:
enabled: true
generator:
accessTokenExpiration: 86400
signatures:
secret:
generator:
secret: Test@2020-Ok-Letus-chageit-later
router:
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
swagger-ui:
paths: classpath:META-INF/swagger/views/swagger-ui
mapping: /swagger-ui/**
就像文档说的那样,我还用 Application.java 进行了注释,如下所示-
import io.micronaut.runtime.Micronaut;
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
@OpenAPIDefinition(
info = @Info(
title = "Email Service",
version = "0.0",
description = "Email Service API",
license = @License(name = "Apache 2.0", url = "https://foo.bar"),
contact = @Contact(url = "https://gigantic-server.com", name = "Fred", email = "Fred@gigagantic-server.com")
)
)
public class Application {
public static void main(String[] args) {
Micronaut.run(Application.class);
}
}
完成所有这些之后,当我尝试打开http://localhost:5655/swagger/email-service-0.0.yaml时,它会打开生成的开放 API 规范 yaml。但是,如果我尝试打开http://localhost:5655/swagger-ui/,我会得到 404。请注意,如果我将 security 设置为false一切正常。
谁能帮我解决这个问题?