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 no longer respecting rule overrides #2505

Closed
br-tyler-milner opened this issue Jul 11, 2023 · 4 comments
Closed

Spectral no longer respecting rule overrides #2505

br-tyler-milner opened this issue Jul 11, 2023 · 4 comments

Comments

@br-tyler-milner
Copy link

Describe the bug
Running Spectral outputs linter warnings/errors for paths that have rules turned off via the overrides in my .spectral.yaml. The issues seems to have coincided with the update of the spectral-core dependency from version 1.18.1 to version 1.18.2 as my builds were working fine before that update was made.

To Reproduce
I created a sample project that demonstrates this issue, which includes detailed steps to reproduce. Abbreviated steps below:

  1. Given this OpenAPI document and this .spectral.yaml.
  2. Run this CLI command: spectral lint Demo.yaml --ruleset .spectral.yaml --verbose
  3. See path-casing and resource-names-plural errors produced for paths./v2.1/users/{userId}, which is configured to disable those rules via rule overrides.

Expected behavior
No errors should be output.

Screenshots
image

Environment:

  • Library version: 6.8.0 (also observed using Spectral 0.6.6)
  • OS: macOS 13.4.1 and Ubuntu 22.04
  • Browser: N/A

Additional context
See README in sample project linked above for additional details.

@P0lip
Copy link
Contributor

P0lip commented Jul 12, 2023

Hey!
JSON pointer in the URI should be percent-encoded, thus you'd need to change overrides to

overrides:
  - files:
      - "reference/Demo.yaml#/paths/~1v2.1~1users~1%7BuserId%7D"
      - "reference/Demo.yaml#/paths/~1user"
    rules:
      resource-names-plural: "off"

  - files:
      - "reference/Demo.yaml#/paths/~1v2.1~1users~1%7BuserId%7D"
    rules:
      path-casing: "warn"

LMK if you have any questions.

@br-tyler-milner
Copy link
Author

Thanks, @P0lip! I can confirm that encoding the { } curly braces with %7B and %7D does work. Feel free to close this when ready, but it would be great if the Overrides Spectral documentation page could be updated to incorporate these new encodings as it currently only mentions needing to encode / --> ~1 and ~ --> ~0 and still shows example code that contains unencoded curly braces.

br-tyler-milner added a commit to br-tyler-milner/spectral-rule-override-bug that referenced this issue Jul 12, 2023
@P0lip
Copy link
Contributor

P0lip commented Jul 12, 2023

Good point re the docs - will do.

To give you some extra context behind that change - that's been a bug for a few years in a library that's used across our entire ecosystem.
That gap was closed in stoplightio/json#122, but that resulted in a slight change in the behavior which you observed here.
Long story short - JSON Pointers (the most common usage in Spectral) must be percent-encoded when used inside of URIs

If you want to get the right pointer, you can run Node.js REPL

node # REPL should open

and then run

require('@stoplight/json').pathToPointer(['abc', 'def', '{}']) # this will output you the valid pointer to use in the URI

Alternatively, go to https://npm.runkit.com/@stoplight/json and run it there

image

@P0lip
Copy link
Contributor

P0lip commented Jul 24, 2023

Docs got updated in 69403c1

@P0lip P0lip closed this as completed Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants