While trying to perform a PUT command using a JSON body, the "Validate Against OpenAPI Document" assertion is throwing a validation error:
PAYLOAD:
{
"addressLine1": "123 Maple Lane",
"addressLine2": "<encoded>",
"city": "<encoded>",
"state": "<encoded>",
"postalCode": "<encoded>",
"country": "<encoded>",
"phoneNumber": "<encoded>",
"phoneNumberType": "<encoded>"
}
ERROR: [Path '/addressLine1'] ECMA 262 regex '^[^\p{C}]+$' does not match input string '123 Maple Lane'
It appears the assertion is using pattern ^[^\\p{C}]+$ instead of the defined ^[^\p{C}]+$ in the OAS document.
In other words, the validator is not appropriately handling the \ JSON escape character.
API Gateway 11.1
There is an issue with the OpenAPI validator we are using. The swagger-request-validator-core library uses com.github.fge:json-schema-validator, which validates patterns using Java's java.util.regex.Pattern. This is causing different interpretations of the regex patterns, resulting in unexpected validation failures.
For now, the following are the workarounds when updating your spec:
1. Use Java's \p{Cntrl} pattern: '^[^\p{Cntrl}]+$'
or
2. Use ASCII control character range pattern: '^[^\x00-\x1F\x7F]+$'