Tests and ScriptsScriptExternal Libraries

External Libraries

Bruno allows you to load any npm module for use in your scripting workflows.

Prerequisites

Before you begin, ensure that you have the following:

  1. Node.js installed on your system.
  2. Bruno installed.

Project Structure

The folder structure for this example will be:

    • openspec.yaml
    • .spectral.yml
    • package.json
    • bruno.json

Configuration

You need to initialize package.json file inside your collection.

Navigate to your Bruno collection directory in the terminal.

cd path/to/your/bruno-collection

Initialize package.json file inside your collection.

npm init -y

Now you can install any npm package or module to use in your collection.

Spectral Integration

In this example we’re using Spectral CLI as a npm package which help you to validate OpenSpec API YAML or JSON files with the built-in ruleset.

You need to have OpenAPI JSON or YAML file to work with spectral or you can download from here as example.

Spectral CLI Setup

You can install spectral-cli by running following command:

npm install @stoplight/spectral-cli

Run this command in your terminal to initialize .spectral.yml file which is predefined ruleset.

echo 'extends: ["spectral:oas", "spectral:asyncapi", "spectral:arazzo"]' > .spectral.yaml

Validate your openapi.yaml file from Bruno collection by running following CLI command:

spectral lint openspec.yaml --r .spectral.yaml

Output Overview

After following the process outlined above, warning messages will be displayed on the CLI such as duplicates and empty tags. This is how you can validate your OpenSpec files using Spectral.

openspec.yaml:
 2:6  warning  info-contact    Info object must have "contact" object.      info
 10:9 warning  operation-tags  Operation must have non-empty "tags" array.  paths./pets.get
 36:9 warning  operation-tags  Operation must have non-empty "tags" array.  paths./pets/{petId}.get