Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge instead of replace #76

Open
liemle3893 opened this issue Feb 15, 2022 · 2 comments
Open

Merge instead of replace #76

liemle3893 opened this issue Feb 15, 2022 · 2 comments

Comments

@liemle3893
Copy link

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?

@WindomZ
Copy link
Owner

WindomZ commented Feb 16, 2022

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
Copy link
Owner

WindomZ commented Feb 16, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants