How can I use custom linting with Inso CLI?
Create a Spectral ruleset in YAML format, and upload it to the OAS file in Insomnia by clicking the upload icon for the Default OAS Ruleset.
On the Spec tab of your Insomnia API Collection, click the upload icon for the Default OAS Ruleset and add a Spectral ruleset YAML file with your custom ruleset.
For this task, you need an API Collection that contains an OpenAPI spec. This task uses the KongAir Flights Service specification.
Click the following button to import the specification into Insomnia.
A new Flights Service 0.1.0 API Collection is created, with the specification in its Spec tab.
Insomnia provides a default linting ruleset. Override it to add your custom linting rules by following these steps:
The custom ruleset overrides the default one. To create a new ruleset, add your rules in the file using the Spectral syntax. If you want to extend an existing ruleset, specify the ruleset with the extends property.
Available Spectral top level properties in Insomnia are
rulesandextends. Custom functions are not permitted. However, Insomnia provides support for Spectral built-in core functions.
For example, to extend the default Spectral OpenAPI ruleset to add a warning when tags don’t have a description, add the following content to your ruleset file:
extends: spectral:oas
rules:
tag-description:
description: Tags must have a description.
given: $.tags[*]
severity: warn
then:
field: description
function: truthyThis places the ruleset file in the local working directory. Insomnia renames this custom ruleset as .spectral.yaml.
You can view the content of the file by clicking Custom Ruleset in Insomnia. If you want to make changes to the file, edit it locally.
In this example, you can confirm the rule triggers by removing the description for the GET /flights endpoint. This will be flagged since the ruleset doesn’t allow tags without a description:
"/flights":
get:
summary: Get KongAir planned flights
tags:
- flight-dataThis causes a new warning to appear:
tag-description Tags must have a description.Override the linting rules and use another ruleset, by using either Inso CLI or .spectral.yaml:
Make sure users in your team are running at least Insomnia
13.0to avoid compatibility issues with this feature.
How can I use custom linting with Inso CLI?
Create a Spectral ruleset in YAML format, and upload it to the OAS file in Insomnia by clicking the upload icon for the Default OAS Ruleset.