swagger-merger
swagger-merger copied to clipboard
Merge instead of replace
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?
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"
}
}
}
}
}
I noticed the problem was using the /
symbol, I'll take the time to upgrade, thanks for the feedback!