You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Turning off `update-notifier`](#turning-off-update-notifier)
44
61
-[License](#license)
45
62
63
+
<!-- tocstop -->
64
+
46
65
## Installation
47
66
48
67
### Install with NPM (recommended)
@@ -77,7 +96,7 @@ Once pulled, the container can be run directly, but mount a volume containing th
77
96
### Command line
78
97
`lint-openapi [options] [command] [<files>]`
79
98
80
-
#### [options]
99
+
#####[options]
81
100
- -s (--report_statistics) : Print a simple report at the end of the output showing the frequency, in percentage, of each error/warning.
82
101
- -e (--errors_only) : Only print the errors, ignore the warnings.
83
102
- -d (--default_mode) : This option turns off [configuration](#configuration) and runs the validator in [default mode](#default-mode).
@@ -91,17 +110,17 @@ Once pulled, the container can be run directly, but mount a volume containing th
91
110
92
111
_These options only apply to running the validator on a file, not to any commands._
93
112
94
-
#### [command]
113
+
#####[command]
95
114
`$ lint-openapi init`
96
115
- init : The `init` command initializes a `.validaterc` file, used to [configure](#configuration) the validator. It can also be used to reset the configurable rules to their default values.
97
116
98
-
#### [command]
117
+
#####[command]
99
118
`$ lint-openapi migrate`
100
119
- migrate : The `migrate` command migrates a `.validaterc` file from the legacy format to the current format, retaining all custom rules. The new format is required - this command provides an option to keep custom rules without manually updating the file or initializing a new configuration file with all rules set to the defaults using `lint-openapi init`.
101
120
102
121
_None of the above options pertain to these commands._
103
122
104
-
#### \<files>
123
+
#####\<files>
105
124
- The OpenAPI document(s) to be validated. All files must be a valid JSON or YAML (only .json, .yml, and .yaml file extensions are supported).
106
125
- Multiple, space-separated files can be passed in and each will be validated. This includes support for globs (e.g. `lint-openapi files/*` will run the validator on all files in `files/`)
107
126
@@ -160,6 +179,11 @@ Specific validation "rules" can be turned off, or configured to trigger an error
160
179
Some validations can be configured even further, such as switching the case convention to validate against for parameter names.
161
180
Additionally, certain files can be ignored by the validator. Any glob placed in a file called `.validateignore` will always be ignored by the validator at runtime. This is set up like a `.gitignore` or a `.eslintignore` file.
162
181
182
+
The validator also employs the [`Spectral`](https://github.com/stoplightio/spectral) validation/linting engine to detect certain issues in the API document.
183
+
Spectral rules can also be configured to trigger an error, warning, info, or hint message in the validator output with the `.spectral.yaml` configuration file.
184
+
Spectral further supports the creation of custom rules using a simple but powerful yaml syntax or custom Javascript functions.
185
+
See the [Spectral configuration](#spectral-configuration) section for more details.
186
+
163
187
### Setup
164
188
To set up the configuration capability, simply run the command `lint-openapi init`.
165
189
This will create (or overwrite) a `.validaterc` file with all rules set to their [default value](#default-values). This command does not create a `.validateignore`. That file must be created manually. These rules can then be changed to configure the validator. Continue reading for more details.
@@ -464,6 +488,74 @@ The default values for each rule are described below.
464
488
| duplicate_sibling_description | warning |
465
489
| incorrect_ref_pattern | warning |
466
490
491
+
### Spectral configuration
492
+
493
+
Currently the validator configures Spectral to check the following rules from its
This ruleset has the alias `ibm:oas`, and you can "extend" this ruleset or specify your own custom ruleset
519
+
with a [Spectral ruleset file](https://meta.stoplight.io/docs/spectral/docs/getting-started/3-rulesets.md).
520
+
Note that all of the rules in the `spectral:oas` ruleset are defined in `ibm:oas` but only the rules listed above are enabled by default.
521
+
522
+
You can provide a Spectral ruleset file to the IBM OpenAPI validator in a file named `.spectral.yaml`
523
+
in the current directory or with the `--ruleset` command line option of the validator.
524
+
525
+
#### Changing rule severity
526
+
527
+
Any rule in the `ibm:oas` ruleset can be configured to trigger an error, warning, info, or hint message in the validator output.
528
+
For example, to configure the `openapi-tags` rule to trigger an `info` message instead of a `warning`, specify the following in your Spectral ruleset file:
529
+
```
530
+
extends: ibm:oas
531
+
rules:
532
+
openapi-tags: warn
533
+
```
534
+
535
+
To completely disable a rule, use the severity of `off`.
536
+
For example, to disable the `operation-tags` rule, specify the following in your Spectral ruleset file:
537
+
```
538
+
extends: ibm:oas
539
+
rules:
540
+
operation-tags: off
541
+
```
542
+
543
+
Since the `ibm:oas` ruleset includes all the rules in `spectral:oas`, you can also enable rules from that ruleset that are disabled by default in `ibm:oas`.
544
+
For example, to enable the `info-contact` rule with it's default severity (`warning`), specify the following in your Spectral ruleset file:
545
+
```
546
+
extends: ibm:oas
547
+
rules:
548
+
info-contact: true
549
+
```
550
+
551
+
You could also set the severity of `info-contact` explicitly to `error`, `warn`, `info`, or `hint`.
552
+
553
+
#### Custom rules
554
+
555
+
You can also specify custom rules in the Spectral ruleset file.
556
+
Custom rules can be specified using a simple but powerful yaml syntax or with custom Javascript functions.
557
+
See the Spectral documentation for detailed documentation on [Spectral custom rules](https://meta.stoplight.io/docs/spectral/docs/guides/4-custom-rulesets.md).
558
+
467
559
## Warnings Limit
468
560
469
561
You may impose a warning limit on your API definitions. If the number of warnings issued exceeds the warning limit, the **exit code will be set to 1**. If the Validator is part of your CI build, this will cause the build to fail.
0 commit comments