Skip to content

Clarification on pattern regex literals #1985

@ricellis

Description

@ricellis

The 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.:

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:

  1. myregexbody
  2. /myregexbody/
  3. /myregexbody/myregexflags

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions