stoplightio / spectral

A flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI v3.1, v3.0, and v2.0 as well as AsyncAPI v2.x.
https://stoplight.io/spectral
Apache License 2.0
2.43k stars 235 forks source link

Percent-encoding JSON Pointers in #2511 introduced a breaking change in spectral-core and spectral-cli #2515

Open dlkj opened 1 year ago

dlkj commented 1 year ago

Describe the bug

2511 has introduced a breaking change for rule override JSON Pointers. Different minor versions of spectral-core require different rule override files.

To Reproduce

  1. create an override with a character that could be percent encoded, for example:
    extends: ruleset.yaml
    overrides:
    - files:
      - openapi.yaml#/resource:custom-method/post/requestBody
    rules:
      my-rule: off
  2. override works with spectral-core 1.18.2
  3. override fails with spectral-core 1.18.3
  4. changing the override to the following fixes 1.18.3 but breaks 1.18.2. Note the changing of ":" to "%3A"
    extends: ruleset.yaml
    overrides:
    - files:
      - openapi.yaml#/resource%3Acustom-method/post/requestBody
    rules:
      my-rule: off

Expected behavior

This should have been released as a breaking change, requiring a bump of the spectral-cli version number. Currently we have 6.6.0 of stoplight/spectral-cli showing both of theses behaviours depending on when it was installed from NPM (and which version of spectral-core was resolved.

Environment (remove any that are not applicable):

anikitin commented 1 year ago

Faced similar issue with curly brackets in path overrides. Replaced them in my rules with %7B and %7D, it fixed the issue. At the same time Spectral VS Code plugin still operates with old version of spectral-core and doesn't recognize this escaped syntax properly. So as a workaround need to duplicate override rules in old and new format to support both CLI and VS Code.

mnaumanali94 commented 3 months ago

Need to update vs code extension here: https://github.com/stoplightio/vscode-spectral/issues/216

Would that solve the issue for y'all?

anikitin commented 3 months ago

@mnaumanali94

Need to update vs code extension here: stoplightio/vscode-spectral#216

Would that solve the issue for y'all?

I think at least it would help make my rule definition cleaner. This is what we experience often: VS Code extension is not updated promptly with the latest version of Spectral Core, so the way how our CI works with its up-to-date spectral-cli version does not necessarily replicate what our developers see in their VS Code interface. So, I think that more regular updates of VS Code extension after core updates would help to avoid such kinds of issues.