Andrew Ripley
12/29/2023, 10:29 PM"or"
operator. the goal is to validate that an optional body parameter (if present) has either 0, 1, or 2 items and each item must be either "rx" or "alcohol". this is tricky because absent, empty, 1, and 2 should all be allowed as specific cases.
{
"matchesJsonPath": {
"expression": "$.restrictions",
"or": [
{
"matches": "[]"
},
{
"matches": "(rx|alcohol)"
},
{
"matches": "(rx|alcohol),(rx|alcohol)"
},
{
"absent": true
}
]
}
}
the absent
option is not being respected as a valid option. this is the body i send to the stub:
{}
Any ideas on how I could approach this?
I have also tried going the route of validating the values separate from validating the size:
{
"matchesJsonPath": {
"expression": "$.restrictions.size()",
"or": [
{
"matches": "0"
},
{
"matches": "1"
},
{
"matches": "2"
},
{
"absent": true
}
]
}
}
but the array.size() rule fails when array is absent 😞.Oleg Nenashev
12/30/2023, 9:46 AMTom
01/02/2024, 10:21 AM{
"request": {
"method": "POST",
"urlPath": "/data",
"bodyPatterns": [
{
"or": [
{
"matchesJsonPath": {
"expression": "$.restrictions.size()",
"or": [
{
"matches": "0"
},
{
"matches": "1"
},
{
"matches": "2"
}
]
}
},
{
"matchesJsonPath": {
"expression": "$.restrictions",
"absent": true
}
}
]
}
]
},
"response": {
"status": 200,
"body": "\nOK\n"
}
}
Andrew Ripley
01/02/2024, 7:52 PMAndrew Ripley
01/02/2024, 7:53 PMTom
01/02/2024, 8:02 PMAndrew Ripley
01/02/2024, 8:27 PM