4

有什么我想念的吗?有在本地工作的代码,部署时我得到

ReferenceError:未定义 SwaggerUIBundle

清除浏览数据后,我在本地也遇到了同样的错误。以下是配置:

构建.gradle

    implementation("io.swagger.core.v3:swagger-core:2.0.9")
    implementation("org.webjars:swagger-ui:3.24.3")
    implementation("io.github.classgraph:classgraph:4.8.34")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.10.1")

应用程序.kt

fun main() {
    val app = Javalin.create { config ->
        config.enableCorsForAllOrigins()
        config.showJavalinBanner = false
        config.enableWebjars()
        config.registerPlugin(getConfiguredOpenApiPlugin())
    }
    configureApp(app, Config)
    app.start(7000)
}

fun getConfiguredOpenApiPlugin() = OpenApiPlugin(
    OpenApiOptions(
        Info().apply {
            version("1.0")
            description("Polaris API")
        }
    ).apply {
        activateAnnotationScanningFor("search")
        path("/swagger-docs")
        swagger(SwaggerOptions("/swagger").title("Polaris Swagger Documentation"))
    }
)

Endpoint.kt注释

    @OpenApi(
        description = "Description",
        path = "/get/something",
        method = HttpMethod.GET
    )
    override fun handleEndpoint(ctx: Context) {
       // Code here
    }

作为参考,Javalin 文档:https ://javalin.io/plugins/openapi

此外,我将从浏览器控制台附加所有错误。3.22.2当我3.24.3在 build.gradle 中设置 swagger-ui 版本时,它正在寻找文件。

The script from “http://localhost:7000/webjars/swagger-ui/3.22.2/swagger-ui-bundle.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type.

The script from “http://localhost:7000/webjars/swagger-ui/3.22.2/swagger-ui-standalone-preset.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type.

Loading failed for the <script> with source “http://localhost:7000/webjars/swagger-ui/3.22.2/swagger-ui-bundle.js”.
The script from “http://localhost:7000/webjars/swagger-ui/3.22.2/swagger-ui-standalone-preset.js” was loaded even though its MIME type (“text/plain”) is not a valid JavaScript MIME type.

Loading failed for the <script> with source “http://localhost:7000/webjars/swagger-ui/3.22.2/swagger-ui-standalone-preset.js”.

ReferenceError: SwaggerUIBundle is not defined
4

0 回答 0