打开招摇过市的UI给出404与Micronaut



遵循此处的文档-https://micronaut-projects.github.io/micronaut-openapi/1.3.4/guide/index.html

我将我的build.gradle配置为包括编译时任务,用于生成swagger yaml,如下所示-

tasks.withType(JavaCompile){
options.encoding = "UTF-8"
options.compilerArgs.add('-parameters')
options.fork = true
options.forkOptions.jvmArgs << '-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop'
}

这就是我的application.yaml的样子-

micronaut:
server:
port: 9090
cors:
enabled: true
router:
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
redoc:
paths: classpath:META-INF/swagger/views/redoc
mapping: /redoc/**
rapidoc:
paths: classpath:META-INF/swagger/views/rapidoc
mapping: /rapidoc/**
swagger-ui:
paths: classpath:META-INF/swagger/views/swagger-ui
mapping: /swagger-ui/**

就像医生说的,我也用Application.java进行了注释,如下所示-

package com.api.backend;
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;
@OpenAPIDefinition(
info = @Info(
title = "API Backend",
version = "0.0",
description = "API backend"
)
)
public class Application {
public static void main(String[] args) {
Micronaut.run(Application.class);
}
}

完成所有这些之后,当我尝试打开http://localhost:9090/swagger/api-backend-0.0.yaml时,它将打开生成的开放API规范yaml。但是,如果我尝试打开http://localhost:9090/swagger-ui/,我会得到一个404

有人能帮我解决问题或提出替代方案吗?

由于所有文件都在swagger-ui内,您能添加以下代码并进行检查吗

router:
static-resources:
default:
enabled: true
mapping: /**
paths: classpath:swagger
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
swagger-ui:
paths: classpath:META-INF/swagger/views/swagger-ui
mapping: /swagger-ui/**

所有步骤对我来说都是正确的。

你能检查一下,在你构建项目后,在你的工件中的META-INF/swagger/views/swagger-ui下创建了一个index.html文件吗。

从maven的角度来看,我们在运行mvn compile后的目标文件夹下看到这一点:target/classes/META_INF/swagger/views/swagger-ui-

配置看起来不错,swagger ui应该可以在浏览器中使用http://localhost:8080/swagger-ui

相关内容

最新更新