How do I combine multiple OpenAPI 3 specification files together?

試著忘記壹切 提交于 2019-12-04 07:56:19

One way to do this is to use the open-source project speccy.

Open the terminal and install speccy by running (requires Node.js):

npm install speccy -g

Then run:

speccy resolve path/to/spec.yaml -o spec-output.yaml

Most OpenAPI tools can work with multi-file OpenAPI definitions and resolve $refs dynamically.

If you specifically need to get a single resolved file, Swagger Codegen can do this. Use Codegen 3.x with openapi: 3.0.x files and Codegen 2.x with swagger: '2.0' files.

CLI example (line breaks added for readability):

java -jar swagger-codegen-cli-3.0.11.jar generate
     -l openapi-yaml
     -i ./path/to/openapi.yaml
     -o ./OUT_DIR
     -DoutputFile=output.yaml

The input file (-i) can be a local file or an URL.

Use -l openapi-yaml to output YAML or -l openapi to output JSON. In Codegen 2.x, use -l swagger-yaml for YAML and -l swagger for JSON.

-DoutputFile is optional, the default file name is openapi.yaml / openapi.json in Codegen 3.x and swagger.yaml / swagger.json in Codegen 2.x.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!