spectral icon indicating copy to clipboard operation
spectral copied to clipboard

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

Open dlkj opened this issue 1 year ago • 3 comments

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
  1. override works with spectral-core 1.18.2
  2. override fails with spectral-core 1.18.3
  3. 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):

  • spectral-cli 6.6.0
  • Node.JS 18.16.0
  • OS: Windows 10, Ubuntu 22.04

dlkj avatar Jul 25 '23 08:07 dlkj

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.

anikitin avatar Aug 08 '23 00:08 anikitin

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

Would that solve the issue for y'all?

mnaumanali94 avatar May 03 '24 14:05 mnaumanali94

@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.

anikitin avatar May 03 '24 21:05 anikitin