繁体   English   中英

如何将openapi本地文件加载到localhost上的swagger? (由 restdocs 生成的文件)

[英]How to load openapi local files into swagger on localhost? (Files generated by restdocs)

我的 api 文档由 restdocs 通过单元测试生成。 尽管它可以很好地满足我的大部分需求,但我仍然缺乏一些不错的 swagger 功能,所以我试图通过将 restdocs 转换为 swagger 来充分利用这两个词。尝试了很长时间后,我终于设法在一些第三方库的帮助下完成它( https://github.com/ePages-de/restdocs-api-spec https://github.com/BerkleyTechnologyServices/restdocs-spec )。 这会在 static 文档文件夹下生成打开的 api 文件。 但是,当我尝试访问 swagger url http://localhost:8081/swagger-ui/index.html时,它不会在那里显示,如果直接在 88432188 上添加 swagger 注释,默认情况下会起作用controller。我可以手动导入 openapi yml 文件并通过https://editor.swagger.io/查看它,但可能有更好的方法 map swagger 直接从我的代码中自动找到 openapi 文件,这样我就可以继续使用这个默认swagger url?

谢谢你。

 <plugin>
        <groupId>io.github.berkleytechnologyservices</groupId>
            <artifactId>restdocs-spec-maven-plugin</artifactId>
            <version>${restdocs-spec.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <!--suppress MavenModelInspection -->
                        <skip>${skipTests}</skip>
                        <host>localhost:8081</host>
                        <specification>OPENAPI_V3</specification>
                        <outputDirectory>${project.build.directory}/classes/static/docs</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

在此处输入图像描述

在此处输入图像描述

更新

尝试使用资源文件夹下的文档,但仍然出现相同的错误。 我在这里打开了一个包含详细信息的新问题Failed to load api definition when loading files from application properties

![在此处输入图片描述

你需要将openapi规范yml放在资源文件夹中,并在spring启动应用程序的application.properties文件中设置springdoc.swagger-ui.url=/openapi-3.yaml

检查springdoc api 文档

在应用程序属性中需要确保

spring.web.resources.add-mappings=false

不应添加其阻止提供 static 内容。

openapi-3.0.yml也应该放在resources/static文件夹中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM