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

Spectral CLI Hangs on Rule 'sps-paths-no-special-characters' (Regex Match) #26

Open
travisgosselin opened this issue Jul 27, 2022 · 0 comments · Fixed by #27
Open

Spectral CLI Hangs on Rule 'sps-paths-no-special-characters' (Regex Match) #26

travisgosselin opened this issue Jul 27, 2022 · 0 comments · Fixed by #27
Assignees
Labels
bug Issue to be resolved via code change or discussion. hacktoberfest

Comments

@travisgosselin
Copy link
Member

travisgosselin commented Jul 27, 2022

With the rule (https://github.com/SPSCommerce/sps-api-standards/blob/main/rulesets/src/url-structure.ruleset.yml#L88):

sps-paths-no-special-characters:
    message: "A resource MUST only contain lowercase ISO basic Latin alphabet characters, the numeric characters `0-9`, and a hyphen or dash character. Parameters must be camel-cased."
    severity: error
    given: $.paths.*~
    then:
      function: pattern
      functionOptions:
        match: ^([0-9a-z-\/]*({[a-z][0-9a-zA-Z-]+})?)*$

The Spectral CLI seems to hang on failing matches of longer paths. It looks like it eventually will complete but is a performance issue or leak that results in the linting going from 2 seconds to over 60+ minutes.

The following is a simplified example to reproduce:
Spectral Ruleset:

--- .spectral.yml
extends:
  - spectral:oas
rules:
  recommended-path-characters-only:
    message: "A resource MUST only contain lowercase ISO basic Latin alphabet characters..."
    severity: error
    given: $.paths.*~
    then:
      function: pattern
      functionOptions:
        match: '^(\/([0-9a-z-]+|({[0-9a-zA-Z-]+})+)*)+$'

OpenAPI Spec:

--- oas.json
{
    "openapi": "3.0.3",
    "info": {
        "title": "My API",
        "description": "My API Description"
    },
    "paths": {
        "/v1/api/project-retailer/thinking-very-long/{my_test}": {
        }
    }
}

Local execution (with node 16.14.0 and Spectral 6.4.2 (latest at time of writing)):

spectral lint oas.json --ruleset .spectral.yml --verbose

Hangs with the following output frozen:

Found 52 rules (41 enabled)
Linting oas.json

By modifying the path to pass the regex, it passes instantly: /v1/api/project-retailer/thinking-very-long/{myTest} or even shortening the path works instantly as well: /v1/{my_test}.

Small Aside: Looked at rewriting the regex to see if it can be better on performance. This should be better regex using alternates: ^(\/([0-9a-z-]+|({[0-9a-zA-Z-]+})+)*)+$ . No change though, same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue to be resolved via code change or discussion. hacktoberfest
Projects
None yet
2 participants