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 lint when using NPM-provided rulesets does not resolve rulesets #2019

Closed
jamietanna opened this issue Jan 7, 2022 · 9 comments · Fixed by #2022
Closed

spectral lint when using NPM-provided rulesets does not resolve rulesets #2019

jamietanna opened this issue Jan 7, 2022 · 9 comments · Fixed by #2022
Assignees
Labels
released t/bug Something isn't working

Comments

@jamietanna
Copy link
Contributor

Describe the bug

When running spectral lint, via npx, I cannot provide an NPM-based dependency for

A clear and concise description of what the bug is.

To Reproduce

Given the following .spectral.yaml:

extends: 
  - spectral:oas
  - spectral-aws-apigateway-ruleset

And the following openapi.yml:

openapi: 3.1.0
info:
  title: ''
  version: ''
  description: ''
paths: {}

Then running:

./node_modules/.bin/spectral lint openapi.yml
# or
npx @stoplight/spectral-cli lint openapi.yml

Expected behavior

The rules from https://www.npmjs.com/package/spectral-aws-apigateway-ruleset are downloaded and executed

Actual Behaviour

ENOENT: no such file or directory, open '/home/jamie/workspaces/cddo/federated-api-model/schemas/spectral-aws-apigateway-ruleset'

Screenshots

N/A

Environment (remove any that are not applicable):

  • Spectral CLI: 6.1.0
  • OS: Linux

Additional context

N/A

@jamietanna
Copy link
Contributor Author

Could it be this requires the migration through the spectral-rulesset-migrator?

@bhatikuldeep
Copy link

@jamietanna I am experiencing the same behaviour, created NPM package - https://www.npmjs.com/package/api-spectral as per the documentation - https://meta.stoplight.io/docs/spectral/ZG9jOjI1MTky-sharing-and-distributing-rulesets#NPM; however get the same error as you've mentioned above

ENOENT: no such file or directory, open '..api-spectral'

@P0lip P0lip self-assigned this Jan 14, 2022
@P0lip P0lip added the t/bug Something isn't working label Jan 14, 2022
@P0lip
Copy link
Contributor

P0lip commented Jan 14, 2022

Hey there!
It's indeed an issue.
I sorted it out here 65b0a47 but I still need to find a way to test the node_modules resolution in a reasonable way.
This is the only scenario we didn't have covered 😬

@kernwig
Copy link

kernwig commented Jan 19, 2022

Is there a workaround? Perhaps a url to spectral:oas?

@P0lip
Copy link
Contributor

P0lip commented Jan 19, 2022

Hey @kernwig
spectral:oas should work just fine.
I've already opened up a PR with a solution, so the upstream package should be fixed soon.

@kernwig
Copy link

kernwig commented Jan 19, 2022

@P0lip It does not. Installed in a package within an NPM Workspace. ("casa" is a monorepo)

n/m: I had "spectral:oas3". Removing the 3 fixed it.

@jamietanna
Copy link
Contributor Author

Amazing, thanks Jakub! Is there a rough idea of when this may land on NPM?

@stoplight-bot
Copy link
Collaborator

🎉 This issue has been resolved in version @stoplight/spectral-ruleset-migrator-v1.7.2 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@jamietanna
Copy link
Contributor Author

Nice, this now works with:

  "dependencies": {
    "@govuk-data-standards/spectral-ruleset-govuk-public": "^0.1.0",
    "@stoplight/spectral-cli": "^6.1.1",
    "@stoplight/spectral-ruleset-migrator": "1.7.2"
  }

And .spectral.yaml:

extends:
  - '@govuk-data-standards/spectral-ruleset-govuk-public'
formats:
  - "oas3.1"

Thank you! 🙌

Do we know when the next spectral-cli will go out that includes the dependency bump, so we don't need to manually override it?

jamietanna added a commit to co-cddo/federated-api-model that referenced this issue Jan 26, 2022
As we now have a Spectral ruleset published to NPM, we should start
using it in this project to make sure that we're continually using it,
rather than using the out-of-the-box Spectral OpenAPI rules.

This requires that we pin the package using our `package.json`, as well
as using the

Until the spectral-cli is upgraded (as noted in
stoplightio/spectral#2019) we need to
explicitly pull the `spectral-ruleset-migrator` version that includes
the fix for resolving NPM dependencies correctly.
jamietanna added a commit to jamietanna/spectral-action that referenced this issue Jan 26, 2022
As noted in stoplightio/spectral#2019, we
cannot currently use rulesets from NPM, and need to update to the latest
version of `spectral-ruleset-migrator` to pick it up.
jamietanna added a commit to co-cddo/federated-api-model that referenced this issue Jan 26, 2022
As we now have a Spectral ruleset published to NPM, we should start
using it in this project to make sure that we're continually using it,
rather than using the out-of-the-box Spectral OpenAPI rules.

This requires that we pin the ruleset using our `package.json`.

We also need to amend our OpenAPI's `version` to match the rules
required by the ruleset.

Until the spectral-cli is upgraded (as noted in
stoplightio/spectral#2019) we need to
explicitly pull the `spectral-ruleset-migrator` version that includes
the fix for resolving NPM dependencies correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants