I am attempting to edit an OpenAPI specification by changing all parameters to be nullable. A parameter definition looks like this:
{
"name": "foo",
"required": true,
"type": "string"
}
They are contained in a parameters
array that can be anywhere in the document. What I need is to append "x-nullable": true
to any parameter containing a type
property.
Sample data:
{
"parameters": [
{"notype": "x"},
{"type": "x"}
],
"foo": {
"parameters": [
{"type": "y"}
]
},
"bar": {
"baz": {
"parameters": [
{"type": "z"}
]
}
}
}
Desired output:
{
"parameters": [
{"notype": "x"},
{
"type": "x",
"x-nullable": true
}
],
"foo": {
"parameters": [
{
"type": "y",
"x-nullable": true
}
]
},
"bar": {
"baz": {
"parameters": [
{
"type": "z",
"x-nullable": true
}
]
}
}
}
The closest I could get was this:
.. | (.parameters[] | select(.type)) += {"x-nullable":true}
It successfully changes one of the items in my test document, but the results are inconsistent and seem to be based on the structure I choose for sample data.