我正在尝试编辑 OpenAPI 规范,将所有参数更改为可空。参数定义如下:
{
"name": "foo",
"required": true,
"type": "string"
}
它们包含在一个parameters
数组中,可以位于文档中的任何位置。我需要的是附加"x-nullable": true
到包含属性的任何参数type
。
样本数据:
{
"parameters": [
{"notype": "x"},
{"type": "x"}
],
"foo": {
"parameters": [
{"type": "y"}
]
},
"bar": {
"baz": {
"parameters": [
{"type": "z"}
]
}
}
}
期望输出:
{
"parameters": [
{"notype": "x"},
{
"type": "x",
"x-nullable": true
}
],
"foo": {
"parameters": [
{
"type": "y",
"x-nullable": true
}
]
},
"bar": {
"baz": {
"parameters": [
{
"type": "z",
"x-nullable": true
}
]
}
}
}
我能得到的最接近的答案是:
.. | (.parameters[] | select(.type)) += {"x-nullable":true}
它成功更改了我的测试文档中的一项,但结果不一致,并且似乎是基于我为样本数据选择的结构。