Java 为什么使用 springfox 和 Swagger2 时 v2/api-docs 是默认 URL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39401010/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is v2/api-docs the default URL when using springfox and Swagger2?
提问by jpganz18
I'm just starting using swagger following this guide, but I found out something very weird that makes no sense for me.
我刚刚开始按照本指南使用 swagger ,但我发现了一些对我来说毫无意义的非常奇怪的东西。
As far as I remember , the v2/api-docs should be used for when you have docs of the version number 2 of your API.
据我所知,当您拥有 API 版本号 2 的文档时,应使用 v2/api-docs。
So, the default should be only api-docs, but for some strange reason I found that the default is v2/api-docs.
所以,默认值应该只有 api-docs,但出于某种奇怪的原因,我发现默认值是 v2/api-docs。
Checking the library doc I found this.
检查图书馆文档我发现了这个。
How do I override that value without later not being able to use v2? (when my API will reach a v2 but I will also want to show the legacy docs).
如何在以后无法使用 v2 的情况下覆盖该值?(当我的 API 将达到 v2 但我也想显示旧文档时)。
Or maybe my concept of using v2 is wrong? Can someone help me with this?
或者我使用 v2 的概念是错误的?有人可以帮我弄这个吗?
采纳答案by woemler
The /v2/api-docs
URL is the default that SpringFox uses for documentation. The v2
does not refer to your API's documentation version (which can be changed in the Docket
configuration), but the version of the Swagger specification being used. Take a look at the documentation herefor customizing the Swagger documentation URL. In short, you need to modify an environment property to change the URL your documentation will appear at:
该/v2/api-docs
URL是默认是SpringFox使用的文档。该v2
不是指你的API的文档版本(可在更改Docket
配置),但所使用的扬鞭规范的版本。查看此处的文档以自定义 Swagger 文档 URL。简而言之,您需要修改环境属性以更改您的文档将出现在以下位置的 URL:
springfox.documentation.swagger.v2.path=/my/docs
This will change the default URL for the SpringFox Swagger documentation from /v2/api-docs
to whatever you specify. To implement this, add the above property to a new or existing properties file, and then add it as a property source in your Springfox configuration class:
这会将 SpringFox Swagger 文档的默认 URL 更改为/v2/api-docs
您指定的任何内容。要实现这一点,请将上述属性添加到新的或现有的属性文件中,然后将其添加为 Springfox 配置类中的属性源:
@PropertySource("classpath:swagger.properties")
@Configuration
public class SwaggerConfig {...}