Add custom linting rules in Insomnia

Uses: Insomnia
Related Documentation
Related Resources
Minimum Version
Insomnia - 13.0
TL;DR

In your Insomnia document, click the upload icon for the Default OAS Ruleset and add a Spectral ruleset YAML file with your custom ruleset.

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.

Insomnia provides a default linting ruleset. Override it to add your custom linting rules by following these steps:

Define the rules

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 rules and extends. 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: truthy

Upload the ruleset file

  1. In the Insomnia app, navigate to a document with the OAS file you want to lint.
  2. Click the upload icon for Default OAS Ruleset at the bottom of the pane.

This 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.

Validate

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-data

This causes a new warning to appear:

tag-description Tags must have a description.

Override the rules v13+

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.0 to avoid compatibility issues with this feature.

FAQs

Create a Spectral ruleset in YAML format, and upload it to an OAS file document in Insomnia by clicking the upload icon for the Default OAS Ruleset.

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!