Absolutely. To simplify the JQ validation for testing purposes — while still exercising the validation engine and ValidationResult
logic — we can write a basic expression that:
- Produces an error if a required field (e.g.,
bmaController
) is missing or blank. - Produces a warning if a certain condition is met (e.g.,
vendor
is"DELL"
).
Here’s a minimal JQ validation snippet that can be easily tested and reliably produces validation output:
{
"debug": $input,
"errors": {
"bmaController": [
(if ($input.bmaController | tostring | length) == 0 then "bmaController is required" else null end)
]
},
"warnings": {
"vendor": [
(if ($input.vendor | ascii_downcase) == "dell" then "Dell machines may need firmware updates" else null end)
]
}
} | with_entries(select(.value | type == "object") | .value |= with_entries(select(.value != null)))
-
"debug": $input
: Echoes back the input for debugging. -
Errors
- Triggers if
bmaController
is missing or empty.
- Triggers if
-
Warnings
- Triggers if
vendor
is"dell"
(case-insensitive).
- Triggers if
-
with_entries(...)
: Removesnull
entries from botherrors
andwarnings
.
{
"bmaController": "",
"vendor": "dell",
"serialNo": "1234"
}
{
"debug": {
"bmaController": "",
"vendor": "dell",
"serialNo": "1234"
},
"errors": {
"bmaController": ["bmaController is required"]
},
"warnings": {
"vendor": ["Dell machines may need firmware updates"]
}
}
validation:
- type: JQ
name: simplified validation for testing
expr: |
{
"debug": $input,
"errors": {
"bmaController": [
(if ($input.bmaController | tostring | length) == 0 then "bmaController is required" else null end)
]
},
"warnings": {
"vendor": [
(if ($input.vendor | ascii_downcase) == "dell" then "Dell machines may need firmware updates" else null end)
]
}
}
| with_entries(select(.value | type == "object") | .value |= with_entries(select(.value != null)))
Let me know if you’d like a version that incorporates lookup response logic or produces multiple errors/warnings.