如何使用 openapi-generator 生成 API 文档? [英] How to generate API Documentation using openapi-generator?

查看:789
本文介绍了如何使用 openapi-generator 生成 API 文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 OpenAPI 3.0.0 的新手.

I'm new to the OpenAPI 3.0.0.

我已经使用 openapi-generator 成功创建了一个 java 客户端库.

I have successfully created a java client library using an openapi-generator.

但是 OpenAPI Generator 允许生成 API 客户端库(SDK 生成)、服务器存根、文档.所以我想知道是否有任何命令或步骤可用于生成 HTML 文档以及自定义文档模板.

But OpenAPI Generator allows the generation of API client libraries (SDK generation), server stubs, documentation. So I want to know is there any commands or steps are available to generate HTML documentation and also to customize the documentation template.

推荐答案

老问题,但对于那些仍然遇到它的人.OpenApi Generator 可以根据 API 的 yaml 或 json 定义生成 html 文档.

Old question, but for those still bumping into it. OpenApi Generator can do generation of html documentation from your yaml or json definition of your API.

openapi-generator generate -i PathToMyInputDefinitionFile.yaml -g html -o /PathToOutputFolder

其中 html 是您要使用的生成器.其他生成器包括 dynamic-htmlhtml2.也可以作为降价发出.请参阅 https://openapi-generator.tech/docs/generators/

Where html is the generator you want to use. Other generators include dynamic-html and html2. Also can emit as markdown. See https://openapi-generator.tech/docs/generators/

如果使用 Docker,则完整示例如下所示:

If using Docker, a full example would look like this:

docker run --rm -v ${PWD}:/local openapitools/openapi-generator:tagname generate -i /local/input.yaml -g html -o /local

PWD 是主机中的当前工作目录(当前目录),您将其映射到容器中的/local.调整标签名"以适应,来自 https://hub.docker.com/r/openapitools/openapi-generator/tagsinput.yaml 调整为 API 的输入文件 yaml 定义.

PWD is present working directory (current directory) in the host, which you are mapping on to /local in the container. Adjust 'tagname' to suit, from https://hub.docker.com/r/openapitools/openapi-generator/tags Adjust input.yaml to be your input file yaml definition of your API.

这篇关于如何使用 openapi-generator 生成 API 文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆