Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarification on pattern regex literals #1985

Closed
ricellis opened this issue Aug 7, 2019 · 5 comments
Closed

Clarification on pattern regex literals #1985

ricellis opened this issue Aug 7, 2019 · 5 comments

Comments

@ricellis
Copy link
Contributor

ricellis commented Aug 7, 2019

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
@handrews
Copy link
Member

handrews commented Aug 7, 2019

@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. Referencing RegularExpressionBody 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

@ricellis
Copy link
Contributor Author

ricellis commented Aug 8, 2019

Thanks @handrews, I've opened json-schema-org/json-schema-spec#774 for a clarification in the JSON Schema validation spec. I guess there may still be work here to update the link in the OAS spec or also cite that only a RegularExpressionBody is expected.

@ricellis
Copy link
Contributor Author

Note that the JSON Schema spec has been updated (targetting draft-08) to clarify this via json-schema-org/json-schema-spec#775.

As per that clarification; the correct ECMA 262 section to link is 15.10.1 - I've opened PR #1987 to correct the OpenAPI spec link to also point to that section.

@handrews
Copy link
Member

JSON Schema 2019-09 (formerly known as "draft-08") has been published, and OAS PR #1977 is about updating the Schema Object to be compatible with it in OAS 3.1. I think the PR mentioned above is still useful for OAS 3.0, as the JSON Schema draft there will not be changing.

@philsturgeon
Copy link
Contributor

This was fixed in #1977 so we can close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants