得到以下內容:
val commonCompilerArgs = listOfNotNull(
"-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop",
)
tasks {
compileKotlin {
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs = commonCompilerArgs
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "11"
}
}
}
但是得到了這個錯誤:
無效引數:-Dmicronaut.openapi.views.spec=rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop
我想這很簡單,但我不知道如何正確設定這個編譯器引數。
任何幫助表示贊賞!
uj5u.com熱心網友回復:
如果您在 Micronaut 應用程式 gradle 腳本中使用 kapt,那么您可以這樣設定:
kapt {
arguments {
arg(
"micronaut.openapi.views.spec",
"rapidoc.enabled=true,swagger-ui.enabled=true,swagger-ui.theme=flattop"
)
}
}
在注釋處理階段生成開放 API 定義檔案和 Swagger UI,在該階段生成源代碼和資源檔案。這意味著它在compileKotlin任務之前。
部分示例構建輸出:
...
> Task :my-app:kaptGenerateStubsKotlin
> Task :my-app:processResources
> Task :my-app:detekt
> Task :my-app:processTestResources NO-SOURCE
> Task :my-app:kaptKotlin
Note: Generating OpenAPI Documentation
Note: Writing OpenAPI YAML to destination: /home/me/prj/my-app/backend/build/tmp/kapt3/classes/main/META-INF/swagger/my-app-1.0.yml
Note: Writing OpenAPI View to destination: /home/me/prj/my-app/backend/build/tmp/kapt3/classes/main/META-INF/swagger/views/swagger-ui/index.html
Note: Creating bean classes for 9 type elements
> Task :my-app:compileKotlin
> Task :my-app:compileJava NO-SOURCE
> Task :my-app:classes
...
更新:您還必須將Swagger的 micronaut.router.static-resources部分添加到application.yaml組態檔中,以映射 swagger 靜態路由,如下所示:
micronaut:
router:
static-resources:
swagger:
paths: classpath:META-INF/swagger
mapping: /swagger/**
swagger-ui:
paths: classpath:META-INF/swagger/views/swagger-ui
mapping: /swagger-ui/**
然后您可以在 http://localhost:8080/swagger/my-app-1.0.yml 上訪問 OpenAPI 定義檔案,并且 Swagger UI 應該在 http://localhost:8080/swagger-ui 上可用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/425839.html
