-
-
Notifications
You must be signed in to change notification settings - Fork 240
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
docs: config file #270
Merged
Merged
docs: config file #270
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
title: Spectral Config | ||
tags: | ||
- Documentation | ||
- Config | ||
--- | ||
|
||
Spectral CLI supports config files, to avoid typing out CLI options and arguments every single time. | ||
|
||
By default Spectral CLI will look for `spectral.yml` in the current working directory, but it could be any JSON or YAML file if you specify it with the `--config` option. | ||
|
||
## Usage | ||
|
||
```bash | ||
spectral lint openapi.yaml --config=spectral.yaml | ||
``` | ||
|
||
## Example Config | ||
|
||
```yaml | ||
lint: | ||
format: json | ||
ruleset: | ||
- http://apis.example.com/governance/core.yml | ||
- http://apis.example.com/governance/rest.yml | ||
skipRule: | ||
- that-one-rule | ||
- broken-rule | ||
output: tmp/lint-results.json | ||
verbose: true | ||
``` | ||
|
||
Right now Spectral only has the one command: `lint`, but other commands in the | ||
future will have their own config namespace too. | ||
|
||
Here are all the available options, with their default values: | ||
|
||
```yaml | ||
lint: | ||
encoding: utf8 # text encoding to use | ||
format: stylish # stylish, json | ||
output: # filename for output instead of stdout | ||
maxResults: # only show the first X erros | ||
verbose: false # see more output for debugging | ||
ruleset: # array of local files or URLs | ||
quiet: false # see only results | ||
skipRule: [] # array of rule names as strings | ||
``` | ||
|
||
The TypeScript interface here looks like this: | ||
|
||
```typescript | ||
export interface ILintConfig { | ||
encoding: string; | ||
format: ConfigFormat; | ||
maxResults?: number; | ||
output?: string; | ||
ruleset?: string[]; | ||
skipRule?: string[]; | ||
verbose: boolean; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
# Spectral Rulesets | ||
--- | ||
title: Spectral Rulesets | ||
tags: | ||
- Documentation | ||
- Rulesets | ||
--- | ||
|
||
Rulesets are a container for collections of rules. These rules are essentially calling functions Spectral, and by taking parameters you can make these functions do whatever you want. | ||
|
||
First the rule filters your object (JSON/YAML file) down to a set of target values, and then list what function arguments should be passed in. | ||
|
||
## Usage | ||
|
||
```bash | ||
spectral lint foo.yaml --ruleset=path/to/acme-company-ruleset.yaml --ruleset=http://example.com/acme-common-ruleset.yaml | ||
``` | ||
|
||
## Example ruleset file | ||
## Example Ruleset | ||
|
||
We currently support ruleset files in both `yaml` and `json` formats. | ||
|
||
|
@@ -28,8 +37,6 @@ Rules are highly configurable. There are only few required parameters but the op | |
|
||
*TODO: generate this table automatically from the TS file.* | ||
|
||
### Rule | ||
|
||
<table> | ||
<thead> | ||
<tr> | ||
|
@@ -140,14 +147,14 @@ Rules are highly configurable. There are only few required parameters but the op | |
</tbody> | ||
</table> | ||
|
||
### Ruleset validation | ||
## Ruleset Validation | ||
|
||
We use JSON Schema & AJV to validate your rulesets file and help you spot issues early. | ||
|
||
**Example output** | ||
|
||
```bash | ||
spectral lint some-oas.yaml --ruleset acme-company.json | ||
$ spectral lint some-oas.yaml --ruleset acme-company.json | ||
tbarn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Reading ruleset | ||
|
||
|
@@ -158,12 +165,5 @@ Reading ruleset | |
/rules/rule-with-invalid-enum/type should be equal to one of the allowed values | ||
``` | ||
|
||
**Note for developers** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this because I didn't understand what it was talking about. I think we only offer YAML rulesets right now anyhow, and we removed our TS to YAML scrupt, but what is a TS to JSON Schema script? @chris-miaskowski do you know about this? |
||
|
||
Supporting YAML and JSON file validation doesn't come free. | ||
We need to maintain schema files that mirror IRule and IRuleset types (see `/src/meta/*.schema.json`). | ||
Ideally, we would have a script that converts TS type to JSON Schema and keeps the meta files up to date. As of now we have a helper that partially automates the work. | ||
|
||
Execute `yarn schema.update` to recreate the `/src/meta/rule.schema.json`. | ||
It will take `IRule` type from `types.ts` file and automatically update the JSON Schema file we use to validate yaml/json ruleset files. | ||
**Warning**: make sure to update *generic* types. Current tools fails to recognize it properly and e.g. treats `string` as `object`. | ||
These errors should look just like errors you get from Spectral when an API description is invalid, | ||
so use them to fix your rules in the same way. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️