跳转到主要内容

openapi规范扩展工具

项目描述

openapi-ext-tools

openapi规范扩展工具

将多个yaml文件打包成单个openapi.yaml

$ openapi-spec-cli --help
usage: openapi-spec-cli [-h] --spec-path SPEC_PATH
                        [--bundled-spec-path BUNDLED_SPEC_PATH] [--verbose]

optional arguments:
  -h, --help            show this help message and exit
  --spec-path SPEC_PATH
                        set path to openapi spec file
  --bundled-spec-path BUNDLED_SPEC_PATH
                        set path to bundled spec file
  --verbose             set verbose mode

如何使用

目前,仅支持将components对象打包。

tests/fixtures/simple/openapi.yaml是openapi规范文件,部分模式定义在tests/fixtures/simple/schemas.yaml中。

...
    content:
      application/json:
        schema:
          $ref: 'schemas.yaml#/components/schemas/User'
...

例如,User模式定义如下。

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
          format: int64
        username:
          type: string
        firstName:
          type: string
        lastName:
          type: string
        birthday:
          type: string
          format: date
        email:
          type: string
        password:
          type: string
        phone:
          type: string
        userStatus:
          type: integer
          description: User Status
          format: int32

运行openapi-spec-cli来打包yaml文件并创建单个openapi.yaml

$ openapi-spec-cli --spec-path tests/fixtures/simple/openapi.yaml
2019-05-11 11:56:12,337 openapi.spec.ext INFO wrote bundled spec file to "bundled_openapi.yaml"
2019-05-11 11:56:12,402 openapi.spec.ext INFO validating bundled spec: OK

您可以在当前目录中确认bundled_openapi.yaml。然后,schemas.yaml中的所有模式都将移动到bundled_openapi.yaml,并且$ref字段也引用为本地引用。

...
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/User'
...

项目详情


下载文件

下载适合您平台文件。如果您不确定选择哪个,请了解有关安装软件包的更多信息。

源分布

openapi-ext-tools-0.5.1.tar.gz (12.2 kB 查看哈希值)

上传时间: 源代码

构建发行版

openapi_ext_tools-0.5.1-py3-none-any.whl (10.6 kB 查看哈希值)

上传时间: Python 3

由以下支持