I am trying to create a custom rule in swagger to validate all API endpoints must include a Authorization' and 'key' header present except '/health' endpoint.
{
"rules": {
"Require Authorization Header": {
"description": "All operations must include the 'Authorization' header in the request parameters, except for the '/health' endpoint.",
"message": "All operations must include the 'Authorization' header in the request parameters, except for the '/health' endpoint.",
"severity": "error",
"given": "$.paths[?(@ != '/health')][*].parameters",
"then": {
"field": "[?(@.name == 'Authorization' && @.in == 'header')]",
"function": "truthy"
}
}
}
{
"extends": [],
"overrides": [],
"rules": [
{
"name": "Validate Subscription Key Header",
"severity": "error",
"given": "$.paths[*][*].parameters",
"then": {
"field": "[?(@.name == 'Ocp-Apim-Subscription-Key' && @.in == 'header')]",
"function": "truthy"
},
"message": "The 'Ocp-Apim-Subscription-Key' header must be included and marked as required for all endpoints."
}
]
}
But some how this is not working as expected, Is they any way that we can achieve this?