问题描述
localhost/swagger 正在按预期加载,但 remoteserver/swagger 有问题.我是否可以保存生成的 swagger 文档的脱机副本?在尝试调试远程问题时,我可以只向几个用户发送一个 zip 文件.
localhost/swagger is loading as expected for me but remoteserver/swagger is having issues. Is it possible for me to save an offline copy of the swagger documentation that's generated? I can just send a zip file to a few users while I'm trying to debug the remote issue.
推荐答案
如果您由于某种原因无法自己托管 Swagger UI,有很多方法可以向您的用户提供 API 文档.所有建议都假定您有一个 OpenAPI (Swagger) 定义,即 YAML/JSON 文件.如果您不知道 YAML/JSON 文件的位置,您可以从 Swagger UI 网页推断它.
There are lots of ways to provide API docs to your users if you for some reason cannot host Swagger UI yourself. All suggestions assume you have an OpenAPI (Swagger) definition, that is the YAML/JSON file. If you don't know the location of the YAML/JSON file, you can infer it from the Swagger UI web page.
不分先后:
将 YAML/JSON 文件发送给您的用户,并告诉他们在 http://editor 中加载它.swagger.io 以便预览 API 文档.
Send the YAML/JSON file to your users and tell them to load it in http://editor.swagger.io in order to preview the API docs.
将您的 OpenAPI 定义文件导入 SwaggerHub 并在那里托管您的 API 文档.
披露:SwaggerHub 由我工作的公司制作.
Import your OpenAPI definition file into SwaggerHub and host your API docs there.
Disclosure: SwaggerHub is made by the company I work for.
将您的 OpenAPI 定义文件放在任何公共网络服务器上,例如在 GitHub 上创建一个 gist.然后,您可以通过将 API 文档加载到 Swagger UI 公共演示中来呈现 API 文档,如下所示:
Put your OpenAPI definition file on any public web server, e.g. create a gist on GitHub. Then you can render API docs by loading it into Swagger UI public demo, like so:
http://petstore.swagger.io?url=YOUR_YAML_or_JSON_URL
如果使用 gist,请确保指定原始 gist 链接(https://gist.githubusercontent.com/...).如果使用其他主机,请确保主机服务器支持 CORS.
If using a gist, make sure to specify a raw gist link (https://gist.githubusercontent.com/...). If using another hosting, make sure the hosting server supports CORS.
打包"Swagger UI 和您的 OpenAPI 定义到一个单一的无依赖文件如此处解释,并将生成的文件发送给您的用户.
"Pack" Swagger UI and your OpenAPI definition into a single dependency-less file as explained here, and send the resulting file to your users.
生成静态 HTML 文档(不是 Swagger UI,而是一个没有试用"的静态 HTML 页面):将您的 OpenAPI 定义加载到 http://editor.swagger.io,然后选择菜单项Generate Client >html 或 html2 或 dynamic-html.
Generate static HTML docs (not Swagger UI, but a static HTML page without "try it out"): load your OpenAPI definition into http://editor.swagger.io, then select the menu item Generate Client > html or html2 or dynamic-html.
生成客户端"功能使用 Swagger Codegen,所以你也可以使用 CLI 版本的 Codegen生成所需的输出.
The "Generate Client" feature uses Swagger Codegen, so you can also use the CLI version of the Codegen to generate the desired output.
- 想要 PDF 吗?可以将 OpenAPI 定义转换为 PDF.
另见:
- 使用 Swagger 生成静态文档
- 将 Swagger 规范 JSON 转换为 HTML 文档
这篇关于是否可以获得网站的 swagger 文档的离线版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!