OAS validation fails due to RegEx
search cancel

OAS validation fails due to RegEx

book

Article ID: 405722

calendar_today

Updated On:

Products

CA API Gateway

Issue/Introduction

The REST services are validated against OAS. The validation against this RegEx "^([\p{L}.\-\/]+)$" returns an error message:

[Path '/xxxx/xxxx/mimeTyp'] ECMA 262 regex "^([\p{L}.\-\/]+)$" does not match input string "application/pdf", even though the input matches it "application/pdf".

When the RegEx is replaced with another one "^([\w.\-\/]+)$", it works.

OAS example:
...
mimeTyp:
          type: string
          example: application/pdf
          maxLength: 50
          minLength: 0
          pattern: ^([\w.\-\/]+)$
...

Environment

API Gateway11.1

Resolution

In the Layer7 API Gateway, the regex engine is the Java’s Pattern class. \p{L} works and matches any Unicode letter, but in your Open API spec, the pattern keyword must use ECMA 262 regex, which does not support \p{}. Therefore, your validator rejects the pattern as invalid syntax.

Use pattern: ^([\w.\-\/]+)$ in your OpenAPI spec and it will pass all validators.