diff --git a/README.md b/README.md index 41e51f367..183ade9a3 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ Other options include: > Note: The Spectral CLI supports both YAML and JSON. -Currently, the CLI supports validation of OpenAPI documents and lints them based on our default ruleset. It does not support custom rulesets at this time. Although if you want to build and run custom rulesets outside of the CLI, see [Customization](#Customization). +Currently, Spectral CLI CLI supports validation of OpenAPI documents and lints them based on our default ruleset, or you can provide [your own rulesets](docs/rulesets.md). ## Concepts @@ -105,13 +105,13 @@ There are three key concepts in Spectral: **Rulesets**, **Rules** and **Function Think of a set of **rules** and **functions** as a flexible and customizable style guide for your JSON objects. -## Programmatic usage +## Config -Spectral is written in TypeScript (JavaScript) and can be used directly for when you need to use Spectral programatically. Take a look at our ["JavaScript API documentation"](docs/js-api.md). +Spectral CLI supports [config files](docs/config.md), to avoid typing out CLI options and arguments every single time. -## Rulesets +## Programmatic usage -You can find all about [rulesets here](docs/rulesets.md). +Spectral is written in TypeScript (JavaScript) and can be used directly for when you need to use Spectral programmatically. Take a look at our ["JavaScript API documentation"](docs/js-api.md). ## FAQs diff --git a/docs/config.md b/docs/config.md new file mode 100644 index 000000000..672282b7e --- /dev/null +++ b/docs/config.md @@ -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; +} +``` diff --git a/docs/rulesets.md b/docs/rulesets.md index 26b37cece..094a0a3e3 100644 --- a/docs/rulesets.md +++ b/docs/rulesets.md @@ -1,4 +1,13 @@ -# 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 @@ -6,7 +15,7 @@ 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 -