[英]Opening swagger UI gives 404 with Micronaut
我將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);
}
}
After doing all this, when I try to open http://localhost:9090/swagger/api-backend-0.0.yaml
it opens the generated open API spec 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 文件夾下看到這個:target/classes/META_INF/swagger/views/swagger-ui
配置看起來不錯,swagger-ui 應該在瀏覽器中可用http://localhost:8080/swagger-ui
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.