Add custom linting rules in Insomnia

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

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.

Prerequisites

Download and install Insomnia.

For this task, you need an API Collection that contains an OpenAPI spec. This task uses the KongAir Flights Service specification.

  1. Click the following button to import the specification into 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 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:

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 the API Collection with the OAS file you want to lint.
  2. Click the Spec tab.
  3. 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 the OAS file 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!