Open
Description
Describe the bug
spectral incorrectly flags an example corresponding to a valid regexp pattern as invalid.
JSON Schema says that patterns should be processed as Unicode regexp, but it appears that the fix #1787 for #1782 turned off unicodeRegExp
:
unicodeRegExp: false,
Thus for the following property
openapi: 3.1.0
components:
schemas:
label:
description: The human readable label for the report type.
type: string
minLength: 1
maxLength: 55
pattern: '^\P{Cc}{1,55}$'
example:
Admin User Activity
We get
11:9 error oas3-valid-schema-example "example" property must match pattern "\P{Cc}{1,55}" components.schemas.label.example
even though this is a valid example that matches the regex
> 'Admin User Activity'.match(/^\P{Cc}{1,55}$/u)
'Admin User Activity'.match(/^\P{Cc}{1,55}$/u)
[
'Admin User Activity',
index: 0,
input: 'Admin User Activity',
groups: undefined
]
>
To Reproduce
- Save the sample as
openapi.yaml
- Run this CLI command
echo 'extends: spectral:oas' > .spectral.yaml
spectral lint openapi.yaml
- See error
11:9 error oas3-valid-schema-example "example" property must match pattern "\P{Cc}{1,55}" components.schemas.label.example
Expected behavior
no false negative error for a valid pattern that matches a pattern with a charset pattern
Since a bug fix intentionally disables Unicode, and enabling it may break others, I would like an option to enable it,
either in the CLI options or in the spectral ruleset.
Environment (remove any that are not applicable):
- Library version: spectral cli 6.4.2
- OS: MacOS 13.2.1
- Browser: n/a