npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

flexbench-openapi-module

v1.1.0

Published

A module to parse OpenAPI documents and generate test scenarios.

Readme

Flexbench OpenAPI Module

This module parses OpenAPI documents and generates test scenarios in the form of .flex files and cURL commands for use with Flexbench.

Prerequisites

  • Node.js: Ensure you have Node.js installed, preferably the latest LTS version. Verify the installation with:
node -v
npm -v

Project Structure

openapi-module/
├── node_modules/               # Dependencies installed via npm
├── sample/                     # Sample files for testing
│   └── sample-openapi.yaml     # Example OpenAPI document
├── scripts/                    # Scripts for generating outputs
│   ├── generate-all.js         # Script to generate both cURL commands and Flex scenarios
│   ├── generate-curl.js        # Script to generate cURL commands
│   └── generate-flex.js        # Script to generate Flex scenarios (.flex files)
├── src/                        # Source files
│   ├── generators/             # Scenario and command generation logic
│   │   ├── curl-generator.js   # Logic for generating cURL commands
│   │   ├── field-mapping.js    # Mapping for generating fake data
│   │   ├── flex-generator.js   # Logic for generating Flex scenarios
│   │   └── gpt-flex-generator.js # Logic for generating Flex scenarios using GPT
│   ├── GPT/                    # GPT related configuration
│   │   └── config.js           # Configuration file for GPT settings
│   ├── parsers/                # Parsing logic
│   │   └── openapi-parser.js   # Logic for parsing OpenAPI documents
│   └── utils/                  # Utility functions
│       └── generation-utils.js # Utility functions for generation scripts
├── temp/                       # Temporary files and generated outputs
├── test/                       # Tests for the module
│   ├── generators.test.js      # Tests for generators
│   └── parser.test.js          # Tests for parsers
├── .gitignore                  # Ignored files and directories
├── package-lock.json           # npm lock file
├── package.json                # npm package file
└── README.md                   # Project documentation

Installation

Install dependencies by running:

npm install

Configuration

OpenAI API Key Setup

If you use GPT for scenario generation, set your OpenAI API key as an environment variable.

Linux/MacOS:

Add the API key to your shell configuration file:

export OPENAI_API_KEY='your-api-key-here'

Reload your shell configuration:

source ~/.bashrc  # or source ~/.zshrc, etc.

Module Configuration (Optional)

The module is pre-configured to work out of the box with sensible defaults. You can modify src/GPT/config.js to customize the behavior:

  • useGPT: Default is false. Set to true to use GPT for generating .flex files.
  • openaiApiKey: Set this in your environment if using GPT.
  • model, maxTokens, temperature: Pre-set for general use, but adjustable for specific needs.
  • promptTemplate: Already tailored to generate useful Flex scenarios. Advanced users can modify it.
  • outputDir, outputFileName: Defaults to saving outputs in the temp directory with a .flex extension.
module.exports = {
    useGPT: false,
    openaiApiKey: process.env.OPENAI_API_KEY,
    model: "gpt-3.5-turbo",
    maxTokens: 1500,
    temperature: 0.7,
    promptTemplate: function(endpoints) {
        return `
        You are given the following API endpoints from an OpenAPI document:

        ${JSON.stringify(endpoints, null, 2)}

        Please generate a Flex scenario JSON file that includes:
        ...
        `;
    },
    outputDir: '../../temp',
    outputFileName: 'flex-scenario-gpt.flex',
};

Usage

Generating .flex Files and cURL Commands

You can generate .flex files and cURL commands using the scripts provided.

Static Approach (Faker)

  1. Run the script with --useGPT=false to use Faker for generating data.
  2. Customize field mappings in field-mapping.js if needed.
  3. Run the scripts.

AI Approach (OpenAI GPT)

  1. Run the script with --useGPT=true to use GPT for generating data.
  2. Ensure your API key is set and the promptTemplate is configured in config.js.
  3. Run the scripts.

Running the Scripts

Generate cURL Commands

Generate cURL commands based on your OpenAPI file:

npm run generate-curl -- --openApiFilePath=sample/sample-openapi.yaml --outputFilePath=./temp/curl-commands.sh

Generate Flex Scenarios

Generate Flex scenarios:

npm run generate-flex -- --openApiFilePath=sample/sample-openapi.yaml --outputFilePath=./temp/flex-scenario.flex --useGPT=true --gptOutputFilename=my-custom-scenario.flex

You can omit the --useGPT=true and --gptOutputFilename arguments to use default settings, which will generate the file as flex-scenario.flex.

Generate Both cURL Commands and Flex Scenarios

Generate both cURL commands and Flex scenarios:

npm run generate-all -- --openApiFilePath=sample/sample-openapi.yaml --curlOutputFilePath=./temp/curl-commands.sh --flexOutputFilePath=./temp/flex-scenario.flex --useGPT=true --gptOutputFilename=my-custom-scenario.flex

Customizing Script Execution

You can control the generation process via command-line arguments:

npm run generate-flex -- --openApiFilePath=sample/sample-openapi.yaml --outputFilePath=./temp/flex-scenario.flex --useGPT=true --gptOutputFilename=my-custom-scenario.flex

Params Explained:

  • --openApiFilePath: Path to your OpenAPI YAML file. Required for all generation scripts.

    • Example: --openApiFilePath=sample/sample-openapi.yaml
  • --outputFilePath: Path to save the generated .flex file or cURL commands. Required for generating .flex files or cURL commands.

    • Example: --outputFilePath=./temp/flex-scenario.flex
  • --curlOutputFilePath: Path to save the generated cURL commands. Required when generating cURL commands, especially with generate-all.js.

    • Example: --curlOutputFilePath=./temp/curl-commands.sh
  • --flexOutputFilePath: Path to save the generated .flex scenarios. Required when generating Flex scenarios, particularly with generate-all.js.

    • Example: --flexOutputFilePath=./temp/flex-scenario.flex
  • --useGPT: Flag to determine whether to use GPT for generating .flex scenarios. Set to true for GPT-based generation, or false for static. Defaults to the setting in config.js.

    • Example: --useGPT=true
  • --gptOutputFilename: Filename for the generated .flex file when using GPT. Optional; defaults to the filename in config.js if not provided.

    • Example: --gptOutputFilename=my-custom-scenario.flex

Using Generated .flex and cURL Files

Mock Server Setup

  1. Install Prism to start a mock server:
npm install -g @stoplight/prism-cli 
  1. Run Prism with your OpenAPI YAML file:
prism mock sample-openapi.yaml -p 4000

Use with Flexbench

  1. Load the generated .flex file into the Flexbench desktop app.
  2. Run the test scenarios directly from the app.

Testing

Running Tests

Run tests for the module:

npm test