openapi cli工具

openapi-cli-tool的Python项目详细描述


openapi-cli-tool

Build Status

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版本。下面是渲染的屏幕截图:

bundle-html-img

列表

列出来自文件/目录的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]:

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
用户界面java,使用gui连接到另一台计算机/服务器的文件系统   运行sbt的ubuntu返回错误:“javahome需要<path>参数”   java如何在Android中处理许多ImageView而不出现内存问题?   查询中非法字符的java相同URL失败   安卓取消引用可能会产生“java”。lang.NullPointerException'   java中的indexoutofboundsexception“java.lang.ArrayIndexOutOfBoundsException”错误   xml Java将dom保存到文件>文件在程序结束后由另一个进程打开   Java的垃圾收集器是如何工作的?   Java如何筛选值(列表)   java处理字符串我怎样才能像在真实的书籍中一样在上面部分生成“小数字”呢?   java SonarQube是否有一个API来获取所有项目分析的一部分?   java startActivity(intent)什么都不做   JAVAutil。扫描器类Java   java如何从Firebase更新电子邮件?UpdateMail方法已被弃用   java Hibernate。如何正确组织带有注释的onetomany关系?   在java中获得卷标和驱动器号之间的映射(而不是FileSystemView)的解决方法是什么   java查找文件的路径