Skip to content

Spectal complains when a openapi pattern uses a Unicode character set #2419

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

Open
DavidBiesack opened this issue Mar 14, 2023 · 3 comments · May be fixed by #2809
Open

Spectal complains when a openapi pattern uses a Unicode character set #2419

DavidBiesack opened this issue Mar 14, 2023 · 3 comments · May be fixed by #2809
Labels
enhancement New feature or request triaged

Comments

@DavidBiesack
Copy link

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

  1. Save the sample as openapi.yaml
  2. Run this CLI command
echo 'extends: spectral:oas' > .spectral.yaml
spectral lint openapi.yaml
  1. 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
@P0lip
Copy link
Contributor

P0lip commented Mar 16, 2023

We've already had a discussion around that here #2030.

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.

That's fine by me.
I'm not sure how the option would be named though. It's really specific to schema validation fn.

@DavidBiesack
Copy link
Author

Thanks @P0lip .
Do you know why #2030 was closed? I don't see this as having been resolved.

One option may be to define two schema validation functions, so one could disable one rule (that uses the current function) and enable a different rule that uses the unicode RegExp rule. I don't know exactly how example validation is done (i.e. if it is deep inside the schema validation rule, or if it is separate.

@P0lip
Copy link
Contributor

P0lip commented Mar 23, 2023

Do you know why #2030 was closed? I don't see this as having been resolved.

I don't know, to be frank.

I'll keep this one up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants