Add custom linting rules in Insomnia

Uses: Insomnia
Related Documentation
Related Resources
TL;DR

In your Git repository, add a .spectral.yaml file containing your custom ruleset at the same level as the .insomnia folder.

Prerequisites

Download and install Insomnia.

For this task, you need a design document in Insomnia. We’ll use the KongAir Flights Service specification.

  1. Click the button below to import the specification as a design document in Insomnia.

    Run in Insomnia}

  2. Click RUN FLIGHTS SERVICE, then Open Insomnia.
  3. Click Scan, then click Import.

A new Flights Service 0.1.0 document is created.

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: Missing tag description warning

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!