valid-schema-regex-pattern
Overview
This rule belongs to the openapi-v3-syntax-linting
ruleset and states that:
The value of the string validation keyword pattern
must be a valid regular expression according to the ECMA 262 regular expression dialect. It is recommended to restrict yourself to following regular expression tokens: individual Unicode characters, as defined by the JSON specification [RFC8259], simple character classes ([abc]
), range character classes ([a-z]
), complemented character classes ([^abc]
, [^a-z]
), simple quantifiers: +
(one or more), *
(zero or more), ?
(zero or one), and their lazy versions (+?
, *?
, ??
), range quantifiers: {x}
(exactly x occurrences), {x,y}
(at least x, at most y, occurrences), {x,} (x occurrences or more), and their lazy versions, the beginning-of-input (^
) and end-of-input ($
) anchors.
Property | Value |
---|---|
Enabled | Yes |
Maximum Severity | Warning |
Message | Pattern is invalid. |
Code | OPENAPI3SYNTAX_L140 |
Type | Linting |
Rule System | Syntax |
Broad Category | Schemas |
Products Impacted | API Transformer, Code Generation, Developer Experience Portal |
Tags | openapi3 openapi syntax linting regex pattern pattern string schema validation schema |
Suggested Fixes
- Ensure that the value of the pattern is a valid regex expression.
- Ensure that the value of the pattern is properly escaped i.e. any reserved characters are appropriately handled.
- Ensure that the regex expression is valid according to the ECMA 262 dialect of regular expressions.
- Ensure that the pattern uses allowed tokens only.
For More Information
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-6.4
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.3.3
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#schema-object
- https://datatracker.ietf.org/doc/html/draft-wright-json-schema-validation-00#section-5.8
- https://262.ecma-international.org/5.1/
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#openapi-specification
- https://docs.apimatic.io/rulesets/overview/