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: Clarify --ruleset requirement #2061

Closed
ryotrellim opened this issue Feb 7, 2022 · 3 comments · Fixed by #2063
Closed

Spectral: Clarify --ruleset requirement #2061

ryotrellim opened this issue Feb 7, 2022 · 3 comments · Fixed by #2063
Assignees

Comments

@ryotrellim
Copy link
Contributor

ryotrellim commented Feb 7, 2022

Relevant conversation: https://discord.com/channels/841794018173648916/859895506271600670/939506075525320714

Relevant tickets:
bundesAPI/deutschland#48
#1893
stoplightio/spectral-action#618
#1796

Goal

The first line of https://meta.stoplight.io/docs/spectral/ZG9jOjI1MTg1-spectral-cli will actually throw an error.
i.e., Running spectral lint petstore.yaml immediately after install will likely fail with No ruleset was found.

Solution

Add the two ways to get a ruleset.

Create a Ruleset
Spectral, being a generic YAML/JSON linter, needs a ruleset in order to be able to lint files. There are two ways to do this:

  1. Run this comment to reference our predefined results:
    printf '{\n "extends": ["spectral:oas", "spectral:asyncapi"]\n}\n' > .spectral.json
  2. Create your own ruleset. (Link to Custom ruleset topic.)
@ryotrellim ryotrellim changed the title Clarify --ruleset requirement Spectral: Clarify --ruleset requirement Feb 7, 2022
@pamgoodrich pamgoodrich transferred this issue from another repository Feb 14, 2022
@pamgoodrich pamgoodrich self-assigned this Feb 14, 2022
@P0lip
Copy link
Contributor

P0lip commented Feb 14, 2022

@ryotrellim it's in the readme together with a snippet you can use, literally one of the first sentences you have there.
image

If you intend to lint an OpenAPI or AsyncAPI document, we have a few predefined rulesets you can extend to get Spectral up and running. To reference them, you can run the following command:

@pamgoodrich
Copy link
Contributor

@P0lip : I believe you are saying the doc is correct. I was able to get this command to work locally:

spectral lint openweather.json

Once I had a ruleset named .spectral.yaml with this line at the top:

extends: spectral:oas

I can help come up with some clearer steps if that would help. Let me know.

@P0lip
Copy link
Contributor

P0lip commented Feb 15, 2022

I meant the following segment. There's a command you can run that will get you started. It'll create a .spectral.json file which is everything you need to start linting.

153952391-fe55d32a-824d-422f-8947-963648846cd2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants