How do I combine multiple OpenAPI 3 specification files together?

后端 未结 3 876
难免孤独
难免孤独 2020-12-31 10:37

I want to combine an API specification written using the OpenAPI 3 spec, that is currently divided into multiple files that reference each other using $ref. How

3条回答
  •  轮回少年
    2020-12-31 11:12

    I wrote a quick tool to do this recently. I call it openapi-merge. There is a library and an associated CLI tool:

    • https://www.npmjs.com/package/openapi-merge
    • https://www.npmjs.com/package/openapi-merge-cli

    In order to use the CLI tool you just write a configuration file and then run npx openapi-merge-cli. The configuration file is fairly simple and would look something like this:

    {
      "inputs": [
        {
          "inputFile": "./gateway.swagger.json"
        },
        {
          "inputFile": "./jira.swagger.json",
          "pathModification": {
            "stripStart": "/rest",
            "prepend": "/jira"
          }
        },
        {
          "inputFile": "./confluence.swagger.json",
          "disputePrefix": "Confluence",
          "pathModification": {
            "prepend": "/confluence"
          }
        }
      ], 
      "output": "./output.swagger.json"
    }
    

    For more details, see the README on the NPM package.

提交回复
热议问题