I am working on APIM validate-content policy. This policy validate the incoming request body against the JSON schema we defined. So, when we pass invalid request body it returns 400 status code, response body has Message property and it has details about the error. However, in some cases this Message property doesn't have more details like which property in request body triggered validation.
For example, we have following schema,
{
"type": "object",
"ClientId"
],
"properties": {
"ClientId": {
"type": "string"
},
"name": {
"type": "string"
},
"countryCode": {
"type": "string",
"pattern": "^[+][0-9]{1,4}$"
"description": "Country code"
},
"mobileNumber": {
"type": "string",
"pattern": "^([0-9]{10})$"
},
"dob": {
"type": "string",
"format": "date"
}
"mfj": {
"type": "boolean"
}
"address": {
"$ref": "#/components/schemas/Address"
}
}
}
When we pass some invalid values for CountryCode i.e. 91, the policy validate the request body and return following details in Message property.
Body of the request does not conform to the definition which is associated with the content type application/json. String '91' does not match regex pattern '^[+][0-9]{1,4}$'. Line: 5, Position: 22
If we pass invalid values in mobile i.e. 123, the response will be,
Body of the request does not conform to the definition which is associated with the content type application/json. String '123' does not match regex pattern '^([0-9]{10})$'. Line: 5, Position: 24
The details does not tell about which property has triggered validation. It is good to say that CountryCode or Mobilenumber is invalid in message.
So, is there any way/configuration which will include this information as well. So, caller will get some more meaningful error message.