Java 如何生成离线 Swagger API 文档?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34984820/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 16:12:12  来源:igfitidea点击:

How to generate offline Swagger API docs?

javaspring-mvcspring-bootswaggerspringfox

提问by codeshark

I have a spring boot MVC java Web app. I've been able to integrate Springfox for API documentation. I can visually see all of the APIs when server is up and running.

我有一个 Spring Boot MVC java Web 应用程序。我已经能够将 Springfox 集成到 API 文档中。当服务器启动并运行时,我可以直观地看到所有 API。

How can I generate OFFLINE swagger API documentation? Note: I would not like to use asciidoc or markdown documentation, but I'd like the same swagger API user interface in html files. I'd like so that the links are relative to local directory instead of local host server links. Thanks

如何生成离线 swagger API 文档?注意:我不想使用 asciidoc 或 markdown 文档,但我想在 html 文件中使用相同的 swagger API 用户界面。我希望链接相对于本地目录而不是本地主机服务器链接。谢谢

回答by William Cheng

You can try "HTML" or "Dynamic HTML" under the "Generate Client" menu in https://editor.swagger.io. For any issue/feedback with the static doc, please report in the Swagger CodegenGithub repo.

您可以在https://editor.swagger.io的“生成客户端”菜单下尝试“HTML”或“动态 HTML” 。对于静态文档的任何问题/反馈,请在Swagger CodegenGithub 存储库中报告。

editor.swagger.io leverages https://generator.swagger.ioto generate code and generator.swagger.io (Swagger Generator) is part of the Swagger Codegen project.

editor.swagger.io 利用https://generator.swagger.io生成代码,generator.swagger.io(Swagger Generator)是 Swagger Codegen 项目的一部分。

回答by g00glen00b

Springfox allows you to easily create a Swagger tester/API docs based on your Spring annotations.

Springfox 允许您根据 Spring 注释轻松创建 Swagger 测试程序/API 文档。

Swagger itself has some tools to allow you to generate offline/static documentation:

Swagger 本身有一些工具可以让你生成离线/静态文档:

  • The Swagger Editorhas several ways of generating documentation listed in the Generate Clientmenu
  • The Swagger Codegenmodule allows you to generate a static and dynamic HTML document

Both of them require a Swagger YAML or JSON file. In case you don't have a Swagger definition in YAML/JSON because you're using Springfox, you can use the generated file used for Swagger UI (/v2/api-docs?group=<group name>).

它们都需要 Swagger YAML 或 JSON 文件。如果由于使用 Springfox 而在 YAML/JSON 中没有 Swagger 定义,则可以使用生成的用于 Swagger UI ( /v2/api-docs?group=<group name>) 的文件。

回答by Jerrod Horton

You might take a look at https://www.DynamicApis.com. You can create an API portal and upload your swagger JSON documents. This site takes the Swagger document and generates a much nicer user interface for your API along with some pretty cool tooling.

你可以看看https://www.DynamicApis.com。您可以创建 API 门户并上传您的 swagger JSON 文档。该站点采用 Swagger 文档并为您的 API 生成一个更好的用户界面以及一些非常酷的工具。

Hereis an example of a portal API that has documentation on one of their APIs.

是一个门户 API 示例,其中包含有关其 API 之一的文档。

回答by Sahar Menashe

Swagger has tool for generating offline docs.

Swagger 有用于生成离线文档的工具。

The tool is "Swagger2Markup" which is located @ Github.

该工具是位于@ Github 的“ Swagger2Markup”。

The output of "Swagger2Markup" can be used as an alternative to swagger-ui and can be served as static content.

“Swagger2Markup”的输出可用作 swagger-ui 的替代品,并可用作静态内容。

Here is an Example

这是一个例子

Good luck! :)

祝你好运!:)

回答by Tobi

Pretty-swag is a UI for Swagger Specification V2 capable of generating static HTML an other formats. It is inspired by Swagger Editor.

Pretty-swag 是 Swagger Specification V2 的 UI,能够生成其他格式的静态 HTML。它的灵感来自 Swagger 编辑器。

checkout https://github.com/twskj/pretty-swag

结帐https://github.com/twskj/pretty-swag

回答by Goutham

Open the live swagger HTML. click on expanding all the operations. Then save the HTML as PDF.

打开实时 swagger HTML。单击展开所有操作。然后将 HTML 保存为 PDF。

This should give you a decent PDF API documentation with all the details in it.

这应该会为您提供一个体面的 PDF API 文档,其中包含所有详细信息。