openapi-spec-validator icon indicating copy to clipboard operation
openapi-spec-validator copied to clipboard

OpenAPI 3.0 spec pattern constant validation

Open wittlesouth opened this issue 6 years ago • 0 comments

Description

According to the OpenAPI 3.0 specification for the pattern attribute of a schema object, the pattern provided should comply with ECMA 262 regular expression syntax. The syntax defined in that specification defines regular expression literals as being preceded and trailed by a '/' character, as they are in Javascript/ECMAscript.

Expected behaviour

Pattern specified in a specification as:

pattern: /regular expression/

should be valid, patterns specified without the leading and trailing '/' characters should not.

Actual Behavior

Both

pattern: /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/

and

pattern: ^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$

are valid pattern constants according to the validator. The second should not be valid, unless I'm misreading the two specification documents linked above.

This is a follow up on Connexion issue number 871.

wittlesouth avatar Feb 23 '19 16:02 wittlesouth