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

openapi-mock-generator-cli

v0.1.3

Published

CLI tool to generate mock data from OpenAPI specifications.

Readme

OpenAPI Mock Generator CLI

GitHub License

Overview

OpenAPI Mock Generator CLI is a Node.js-based tool designed to generate mock data from OpenAPI specifications. It simplifies the process of creating mock data for testing and development purposes, ensuring that developers can simulate the OpenAPI response as realistically as possible.

Features

  • Mock Data Generation: Automatically generate mock data based on OpenAPI schemas.
  • Support for Multiple OpenAPI Versions: Compatible with OpenAPI 2.0, 3.0, and beyond.

Prerequisites

Installation

To install the dependencies, use the following command:

pnpm install

Optionally, install the CLI globally:

pnpm add -g openapi-mock-generator-cli

Usage

Command Line Interface (CLI)

  1. Place your OpenAPI specification files in the openapi/ directory or configure the path in the openapiMockGenerator.config.json file using the openApiFilesPath property.
    • The generator will look for OpenAPI files in the specified directory.
    • You can also specify the mock data output directory in the configuration file using outputSchemasPath property. The default output directory is mocks/.
  2. Run the following command to generate mock data:
#npm
npx openapi-mock-generator-cli

# pnpm
pnpm dlx openapi-mock-generator-cli 

Or if you have installed in your project

#npm
npm run openapi-mock-generator-cli
# pnpm
pnpm openapi-mock-generator-cli

Supported Configuration File Names

The CLI will automatically look for a configuration file in your project root.
You can use any of the following names and formats:

| JSON | YAML/YML | JavaScript/TypeScript | |---------------------|---------------------------|----------------------------| | openapiMockGenerator.json | openapiMockGenerator.yaml | openapiMockGenerator.js | | openapiMockGenerator.config.json | openapiMockGenerator.config.yaml | openapiMockGenerator.config.js | | | openapiMockGenerator.yml | openapiMockGenerator.ts | | | openapiMockGenerator.config.yml | openapiMockGenerator.config.ts |

Tip: This flexibility allows you to choose the format that best fits your workflow or CI/CD pipeline.

Using @faker-js/faker for Mock Data

The OpenAPI Mock Generator supports the use of the @faker-js/faker library to generate realistic mock data. You can define custom mock data in your OpenAPI specification by using x-faker extensions.

Example

In your OpenAPI specification, add the x-faker extension to specify the Faker.js method for generating data:

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: string
          x-faker: datatype.uuid
        name:
          type: string
          x-faker: name.findName
        email:
          type: string
          x-faker: internet.email

How It Works

  1. The generator reads the x-faker extensions in your OpenAPI specification.
  2. It uses the specified Faker.js methods to generate mock data for the corresponding fields.
  3. The mock server will return the generated data when the API is called.

Faker.js Documentation

For a full list of available Faker.js methods, refer to the @faker-js/faker documentation.

By leveraging @faker-js/faker, you can create more realistic and meaningful mock data for your APIs.

Project Structure

  • src/: Contains the source code, including helpers and library modules.
    • helppers/: Utility functions for configuration, file handling, logging, and string manipulation.
    • lib/: Core logic for mock generation and OpenAPI reading.
  • mocks/: Predefined mock schemas for testing.
  • openapi/: OpenAPI specification files.
  • coverage/: Code coverage reports.

Testing

Run the test suite using:

pnpm test

License

This project is licensed under the Apache 2.0 License. See the LICENSE file for details.