Add custom linting rules in Insomnia
In your Git repository, add a .spectral.yaml
file containing your custom ruleset at the same level as the .insomnia
folder.
Prerequisites
Create a design document
For this task, you need a design document in Insomnia. We’ll use the KongAir Flights Service specification.
-
Click the button below to import the specification as a design document in Insomnia.
- Click RUN FLIGHTS SERVICE, then Open Insomnia.
- Click Scan, then click Import.
A new Flights Service 0.1.0 document is created.
Synchronize with Git
This example requires a workspace synchronized with Git. You can either clone a repository to import a workspace, or sync an existing workspace with a Git repository.
Create add the file ruleset
In the Git repository connected to your document, create a .spectral.yaml
at the same level as the .insomnia
folder.
Define the rules
The custom ruleset overrides the default one. If you want to create a completely new ruleset, you can simply add your rules in the file using the Spectral syntax. If you want to extend an existing ruleset, specify the ruleset with the extend
property in .spectral.yaml
.
For example, if you want to extend the default Spectral OpenAPI ruleset to add a warning when tags don’t have a description, you can add the following content to .spectral.yaml
:
extends: spectral:oas
rules:
tag-description:
description: Tags must have a description.
given: $.tags[*]
severity: warn
then:
field: description
function: truthy
Synchronize the changes
Commit and push the file on the repository, then pull the changes in Insomnia.
Validate
Close and reopen the document to apply the changes. In this example, you can validate by creating a new tag without a description:
tags:
- name: flight-data
This causes a new warning to appear: