I am currently trying to filter out some path values from a swagger json document, by using jq.
The JSON looks something like this:
{
"swagger": "2.0",
"info": {
"version": "1.0.2",
"title": "Some API"
},
"host": "example.com",
"basePath": "/",
"paths": {
"/api/companies": {
"get": {
"tags": [ "company-tag" ],
"responses": {
"200": {
"description": "OK",
"schema": { "$ref": "#/definitions/CompanyDTO" }
}
}
}
},
"/api/account": {
"get": {
"tags": [ "account-tag" ],
"operationId": "getAccount",
"responses": {
"200": {
"description": "OK",
"schema": { "$ref": "#/definitions/UserDTO" }
}
}
},
"post": {
"tags": [ "account-tag" ],
"operationId": "createAccount",
"responses": {
"200": {
"description": "OK",
"schema": { "$ref": "#/definitions/UserDTO" }
}
}
}
}
}
}
I would like to filter the paths values, so that I can get only the paths that contain a specific tag inside the tags array.
For example: if I want to get the paths for the account-tag the JSON should look like this after filtering:
{
"swagger": "2.0",
"info": {
"version": "1.0.2",
"title": "Some API"
},
"host": "example.com",
"basePath": "/",
"paths": {
"/api/account": {
"get": {
"tags": [ "account-tag" ],
"operationId": "getAccount",
"responses": {
"200": {
"description": "OK",
"schema": { "$ref": "#/definitions/UserDTO" }
}
}
},
"post": {
"tags": [ "account-tag" ],
"operationId": "createAccount",
"responses": {
"200": {
"description": "OK",
"schema": { "$ref": "#/definitions/UserDTO" }
}
}
}
}
}
}
EDIT
Ikegami's second suggestion worked as expected. Here is my final solution