Skip to content

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

@travisgosselin

Description

@travisgosselin

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.

Metadata

Metadata

Labels

bugIssue to be resolved via code change or discussion.hacktoberfest

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions