I have written a JSON schema file for my Kubernetes Helm values files.
The schema defined some required properties. I would like to publish modified schema without all required properties.
Background: With helm, it’s possible to define a subset of the values files. IntelliJ highlights some error on such subset YAML files, since it misses some "required keys". Thats fine in this context, since the YAML files which holds a subset of the configuration will be merged with the base configuration.
Example JSON
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"blackbox": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
},
"required": ["enabled"]
}
},
"required": ["blackbox"]
}
The schema itself is repeatable, the "required" key can also be found in a 9th or 10th nested level. That’s why I need a solution which enables to do it recursively.
The step should be executed in GitHub Action, however any shell based solution is fine, too.
I was trying to play with jq, but I don’t find the way here.
Example Output:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"blackbox": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
}
}
}
}
2
Answers
If you want to delete all
"required"
properties at any level, the following expression should work:?
is the Optional Object Identifier-Index which will suppress errors.Sample output with your given input:
Recursively remove one key
Recursively remove multiple keys