【问题标题】:Swagger UI into dropwizardSwagger UI 进入 dropwizard
【发布时间】:2021-08-04 08:09:47
【问题描述】:

我从 swagger-ui github 添加了文件夹 dist 并在 index.html 中提供了 openapi.yaml 的路径

url: "/openapi/openapi.yaml"

现在我可以通过地址 http://localhost:63342/dropwizard-example/com/example/dropwizard/dist/index.html 或通过文件 index.html 访问来查看 UI

如何通过我的路径提供 UI? 类似于:dropwizard-project-work.com:8080/dist

【问题讨论】:

    标签: swagger-ui dropwizard


    【解决方案1】:

    也许对某人有用。 将 dist 文件夹从 swagger-ui 移动到资源。

    在文件夹 dist 中找到 index.html 并将选项 url 更改为您的 openapi 规范文件路径

    添加 dropwizard-assets 依赖

            <dependency>
                <groupId>io.dropwizard</groupId>
                <artifactId>dropwizard-assets</artifactId>
                <version>{dropwizard.version}</version>
            </dependency>
    

    在初始化方法中添加Bundle

    
        @Override
        public void initialize(Bootstrap<BasicConfiguration> bootstrap) {
                bootstrap.addBundle(new AssetsBundle("/resoursePath", "/uriPath", "index.html"));
        }
    

    现在可以在 localhost:{your port}/{applicationContextPath}/uriPath 上使用 swagger UI

    【讨论】: