在此遵循文档-https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html
我将build.gradle配置为包括如下所示的编译时间任务,用于生成摇摇欲坠的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。请注意,如果我将安全性设置为 false ,则一切正常。
有人可以帮助我解决这个问题吗?
答案 0 :(得分:1)
我遇到了同样的问题,但是它符合以下规则:
micronaut:
security:
enabled: true
intercept-url-map:
-
pattern: /swagger-ui/**
http-method: GET
access:
- isAnonymous()
只需尝试使用两个**
而不是一个。
答案 1 :(得分:0)
根据指南https://micronaut-projects.github.io/micronaut-security/latest/guide/
不必包括GET方法
listA = [1, 3, 5]
listB = [3, 3, 2]
function getPoints(x, y) {
var xPoints = 0, yPoints = 0;
for (var i = 0; i < x.length; i++)
if (x[i] > y[i]) xPoints++
else if (x[i] < y[i]) yPoints++;
return [xPoints, yPoints];
}
console.log(getPoints(listA, listB)); // output: [1,1]
答案 2 :(得分:-1)
您可以在一般端点上使用安全规则 https://discord.js.org/#/docs/collection/master/class/Collection?scrollTo=filter
喜欢
micronaut:
security:
enabled: true
intercept-url-map:
-
pattern: /swagger-ui/*
access:
- isAnonymous()