Micronaut(Gradle和Java)-启用安全性后无法访问Swagger集成视图

问题描述 投票:0回答:1

按照此处的文档-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 = "[email protected]")
    )
)
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,则一切正常。

有人可以帮我解决这个问题吗?

java swagger swagger-ui micronaut micronaut-openapi
1个回答
0
投票

您可以在摇摇欲坠的端点上使用安全规则https://micronaut-projects.github.io/micronaut-security/latest/guide/#interceptUrlMap

like

micronaut:
  security:
    enabled: true
    intercept-url-map:
      -
        pattern: /swagger-ui/*
        access:
          - isAnonymous() 
© www.soinside.com 2019 - 2024. All rights reserved.