valid-schema-pattern-properties-key
Overview
This rule belongs to the openapi-v3-syntax-linting
ruleset and states that:
The unique key of each entry in the Schema Object patternProperties
property 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 | Key provided for the Schema Object patternProperties entry is invalid. |
Code | OPENAPI3SYNTAX_L143 |
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 properties json schema schema |
Suggested Fixes
- Ensure that the key value is a valid regex expression.
- Ensure that the key value 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 regex pattern uses allowed tokens only.
For More Information
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.3.2.2
- https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-6.4
- https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema-object
- 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/