openapi规范的扩展工具
openapi-ext-tools的Python项目详细描述
OpenAPI扩展工具
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
如何使用
当前,捆绑仅支持组件对象。
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:objectproperties:id:type:integerformat:int64username:type:stringfirstName:type:stringlastName:type:stringbirthday:type:stringformat:dateemail:type:stringpassword:type:stringphone:type:stringuserStatus:type:integerdescription:User Statusformat: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'...