Clarification on pattern regex literals
See original GitHub issueThe specification for pattern says
This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect
I think this is extracted verbatim from the JSON Schema validation draft as per #880
However, the section of ECMA262 linked to describes the regular expression literal i.e. / RegularExpressionBody / RegularExpressionFlags
so it is unclear whether “valid regular expression” means the body or the literal.
There are no example usages of regex patterns in the OAS 3.0.2 document that I can see. However, another example of patterns used in OpenAPI that I have found does not include the /
characters around the regex e.g.:
pattern: '^\d{3}-\d{2}-\d{4}$'
from swagger doc
I think it is unclear from the specification (either OAS or JSON schema validation) whether the pattern field is expected to be a complete ECMA 262 regular expression literal, including the /
characters and optionally including flags, or whether it is saying that only a regular expression body is expected.
Tooling behaviour seems a little inconsistent on this too, so I think a clarification would be useful to help tooling developers know which of these 3 types of pattern values should be supported:
myregexbody
/myregexbody/
/myregexbody/myregexflags
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
@ricellis it is definitely 1.
myregexbody
. The correct reference is ECMA 262 Annex A.7, “Regular Expressions”, although given that that section is informative rather than normative there might be some complications on exactly how to cite that. ReferencingRegularExpressionBody
for clarity would probably be a good idea.This should really be filed on the JSON Schema spec repo.
I’ll try to remember to clarify that i
This was fixed in #1977 so we can close this.