swagger-merger icon indicating copy to clipboard operation
swagger-merger copied to clipboard

Merge instead of replace

Open liemle3893 opened this issue 2 years ago • 2 comments

Usecase: Where I have a legacy swagger.json. And now I just want to add new paths/def using swagger-merger instead of editing old file.

Example:

// apis.swagger.json
{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Echo",
    "description": "#### Echos back every URL, method, parameter and header\nFeel free to make a path or an operation and use **Try Operation** to test it. The echo server will\nrender back everything.\n"
  },
  "schemes": [
    "http"
  ],
  "$ref": "./host.yaml",
  "basePath": "/echo",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "$ref": "./responses.json#/components/root/get"
        }
      },
      "post": {
        "responses": {
          "$ref": "./responses.json#/components/root/post"
        },
        "parameters": [
          {
            "$ref": "./name.json"
          },
          {
            "$ref": "./year.json"
          }
        ]
      }
    }
  }
}
// index.json
{
    "$ref": "apis.swagger.json",
    "paths": {
        "/test-path/{id}": {
            "parameters": [
                {
                    "$ref": "./id.json"
                }
            ],
            "get": {
                "responses": {
                    "$ref": "./responses.json#/components/test-path"
                }
            }
        }
    }
}

Expected:

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.0",
    "title": "Echo",
    "description": "#### Echos back every URL, method, parameter and header\nFeel free to make a path or an operation and use **Try Operation** to test it. The echo server will\nrender back everything.\n"
  },
  "schemes": [
    "http"
  ],
  "$ref": "./host.yaml",
  "basePath": "/echo",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "$ref": "./responses.json#/components/root/get"
        }
      },
      "post": {
        "responses": {
          "$ref": "./responses.json#/components/root/post"
        },
        "parameters": [
          {
            "$ref": "./name.json"
          },
          {
            "$ref": "./year.json"
          }
        ]
      }
    },
    "/test-path/{id}": {
      "parameters": [
        {
          "$ref": "./id.json"
        }
      ],
      "get": {
        "responses": {
          "$ref": "./responses.json#/components/test-path"
        }
      }
    }
  }
}

Is there anyway to achieve this?

liemle3893 avatar Feb 15 '22 20:02 liemle3893

Get your Expected through the following index.json:

{
  "$ref": "apis.swagger.json",
  "paths": {
    "$ref#paths": "apis.swagger.json#paths",
    "/test-path/{id}": {
      "parameters": [
        {
          "$ref": "./id.json"
        }
      ],
      "get": {
        "responses": {
          "$ref": "./responses.json#/components/test-path"
        }
      }
    }
  }
}

WindomZ avatar Feb 16 '22 02:02 WindomZ

I noticed the problem was using the / symbol, I'll take the time to upgrade, thanks for the feedback!

WindomZ avatar Feb 16 '22 02:02 WindomZ