openapi generator
OpenAPI 规范(OAS),是定义一个标准的、与具体编程语言无关的RESTful API的规范。OpenAPI 规范使得人类和计算机都能在“不接触任何程序源代码和文档、不监控网络通信”的情况下理解一个服务的作用。如果您在定义您的 API 时做的很好,那么使用 API 的人就能非常轻松地理解您提供的 API 并与之交互了。
如果您遵循 OpenAPI 规范来定义您的 API,那么您就可以用文档生成工具来展示您的 API,用代码生成工具来自动生成各种编程语言的服务器端和客户端的代码,用自动测试工具进行测试等等。
OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (both 2.0 and 3.0 are supported).
代码
支持通过yaml、JSON文件生成几十种客户端和服务端语言,生成的SDK代码十分优雅
JAVA
Python
pip install openapi-python-client
openapi-python-client --install-completion
Create a new client
openapi-python-client generate --url https://my.api.com/openapi.json
This will generate a new client library named based on the title in your OpenAPI spec. For example, if the title of your API is "My API", the expected output will be "my-api-client". You can change that directory name with the config file (documented below) or with --output-path
.
If the directory to generate already exists, you'll get an error unless you use --overwrite
.
You can use an OpenAPI file instead of a URL like openapi-python-client generate --path location/on/disk/openapi.json
.
评论区