简体   繁体   English

是否有可能获得网站的 swagger 文档的离线版本?

[英]is it possible to get an offline version of swagger documentation for a website?

localhost/swagger is loading as expected for me but remoteserver/swagger is having issues. localhost/swagger 正在按预期加载,但 remoteserver/swagger 出现问题。 Is it possible for me to save an offline copy of the swagger documentation that's generated?我可以保存生成的 swagger 文档的离线副本吗? I can just send a zip file to a few users while I'm trying to debug the remote issue.在尝试调试远程问题时,我可以将 zip 文件发送给几个用户。

There are lots of ways to provide API docs to your users if you for some reason cannot host Swagger UI yourself.如果您由于某种原因无法自己托管 Swagger UI,则有很多方法可以向您的用户提供 API 文档。 All suggestions assume you have an OpenAPI (Swagger) definition, that is the YAML/JSON file.所有建议都假设您有一个 OpenAPI (Swagger) 定义,即 YAML/JSON 文件。 If you don't know the location of the YAML/JSON file, you can infer it from the Swagger UI web page .如果您不知道 YAML/JSON 文件的位置,可以从 Swagger UI 网页 推断它

In no particular order:没有特定的顺序:

  1. 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.将 YAML/JSON 文件发送给您的用户并告诉他们在http://editor.swagger.io中加载它以预览 API 文档。

  2. Import your OpenAPI definition file into SwaggerHub and host your API docs there.将您的 OpenAPI 定义文件导入SwaggerHub并在那里托管您的 API 文档。
    Disclosure: SwaggerHub is made by the company I work for.披露:SwaggerHub 是由我工作的公司制作的。

  3. Put your OpenAPI definition file on any public web server, eg create a gist on GitHub.将您的 OpenAPI 定义文件放在任何公共 Web 服务器上,例如在 GitHub 上创建一个要点 Then you can render API docs by loading it into Swagger UI public demo, like so:然后您可以通过将其加载到 Swagger UI 公共演示中来呈现 API 文档,如下所示:

     http://petstore.swagger.io?url=YOUR_YAML_or_JSON_URL

If using a gist, make sure to specify a raw gist link ( https://gist.githubusercontent.com/... ).如果使用要点,请确保指定原始要点链接( https://gist.githubusercontent.com/... )。 If using another hosting, make sure the hosting server supports CORS .如果使用其他主机,请确保托管服务器支持CORS

  1. "Pack" Swagger UI and your OpenAPI definition into a single dependency-less file as explained here , and send the resulting file to your users.如此处所述,将 Swagger UI 和您的 OpenAPI 定义“打包”到一个无依赖关系的文件,并将生成的文件发送给您的用户。

  2. 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 .生成静态 HTML 文档(不是 Swagger UI,而是没有“试用”的静态 HTML 页面):将您的 OpenAPI 定义加载到http://editor.swagger.io ,然后选择菜单项Generate Client > html or html2 or dynamic -html .

The "Generate Client" feature uses Swagger Codegen , so you can also use the CLI version of the Codegen to generate the desired output. “生成客户端”功能使用Swagger Codegen ,因此您还可以使用 Codegen 的 CLI 版本生成所需的输出。

  1. Want a PDF?想要PDF? It's possible to convert OpenAPI definitions to PDF .可以将 OpenAPI 定义转换为 PDF

See also:也可以看看:

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

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