openapi cli工具
openapi-cli-tool的Python项目详细描述
openapi cli工具
openapi(swagger 3.x)cli工具。
- 支持多个文件扩展名(json yaml yml)。
- 可以列出定义的API路径。
- 显示解析的api规范(
$ref
)。 - 将多个文件打包成一个(输出到json yaml html)。
- OAS互动脚手架。
要求
python 2.7、3.4<;=。
安装
使用pip:
$ pip install openapi-cli-tool
手动:
克隆存储库并在计算机上执行python安装命令。
$ python setup.py install
然后安装openapi-cli-tool
命令。
用法
$ openapi-cli-tool --help
Usage: openapi-cli-tool [OPTIONS] COMMAND [ARGS]...
Options:
--help Show this message and exit.
Commands:
bundle Bundle multiple files into one.
list List up API paths in a file or directory.
resolve Display `$ref` resolved API specification.
scaffold Interactively create a simple OpenAPI Specification.
捆绑
将多个文件规范捆绑成一个,而不考虑文件扩展名(json yaml yml)。
$ openapi-cli-tool bundle --help
Usage: openapi-cli-tool bundle [OPTIONS] FILE_PATH
Bundle multiple files into one.
Options:
-f, --file TEXT Load common objects such as info and servers from a
specific file. Default is a file which is the top of list
command result.
-t, --type TEXT Export data type. {json|yaml|html} [default: json]
--help Show this message and exit.
示例:
$ openapi-cli-tool bundle -t html FILE_PATH > ./specification.html
在html文件中,嵌入了swagger-ui的unpkg版本。下面是渲染的屏幕截图:
列表
列出来自文件/目录的api路径,而不考虑文件扩展名(json yaml yml)。
$ openapi-cli-tool list [spec-path] Method Path File -------- --------- ------------------------------------------ PUT /avatar ./tests/resources/spec/sample.yml GET /follwers ./tests/resources/spec/folder1/sample2.yaml POST /follwers ./tests/resources/spec/folder1/sample2.yaml PUT /follwers ./tests/resources/spec/folder1/sample2.yaml POST /pets ./tests/resources/spec/sample.yml GET /posts ./tests/resources/spec/folder1/sample.json POST /posts ./tests/resources/spec/folder1/sample.json GET /users ./tests/resources/spec/folder1/sample.json POST /users ./tests/resources/spec/folder1/sample.json
解决
显示通过$ref指针从多文件api规范解析的api规范。
Usage: openapi-cli-tool resolve [OPTIONS] METHOD PATH FILE_PATH
Display `$ref` resolved API specification.
Options:
-t, --type TEXT Export data type. {json|yaml} [default: json]
--help Show this message and exit.
示例:
$ openapi-cli-tool resolve post /cats ./tests/resources/spec
脚手架
交互式地输入api的信息。
一个简单的openapi规范是从您的提示符生成的。
$ openapi-cli-tool scaffold Please enter title [""]: sample Please enter version [v1.0]: Please enter license [Apache 2.0]: Please enter server url [http://example.com]: Please enter path [/]: /example Please enter method for /example [get|post|put|delete|head|option|trace]: get Please enter description for get /example [""]: sample get endpoint Please enter response code for get /example [200]: