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 🙏

© 2024 – Pkg Stats / Ryan Hefner

openapi-mock-generator

v1.0.0

Published

Create realistic mocked data from an OpenAPI specification, using [faker.js](https://github.com/marak/Faker.js/) and [Chance](https://chancejs.com/) random data generators.

Downloads

4

Readme

OpenAPI Mock Generator

Create realistic mocked data from an OpenAPI specification, using faker.js and Chance random data generators.

Features

  • Support for OpenAPI 3.0 (and 2.0 with conversion to 3.0)
  • Generate realistic mocks for paths/schemas using JSON Schema properties (like format. minimum, maximum, etc...), faker.js or Chance data generators.
  • Autocomplete for OpenAPI properties, Faker.js methods, and Chance methods
  • Multiple projects support with data stored locally in the browser
  • Offline support

Usage

Once you have loaded an OpenApi specification, you can navigate the tree with paths and schemas, and load a definition in the editor. You can modify the selected definition and see the generated mocked data in the editor on the right. The modified definition will be taken also by other elements that have a reference to that definition.

In the tree, there is also a special Playground item that can be used to generate data "on the fly" without modifying an existing definition.

JSON Schema properties examples

Data can be generated from the format property:

{
  "type": "object",
  "properties": {
    "date": {
      "type": "string",
      "format": "date-time"
    },
    "uuid": {
      "type": "string",
      "format": "uuid"
    }
  }
}
{
  "date": "1986-09-22T16:44:15.119Z",
  "uuid": "daf0229f-cc3b-2b50-bbe4-6dea4837b0bf"
}

Number ranges can be controlled with minimum and maximum:

{
  "type": "integer",
  "minimum": 10,
  "maximum": 42
}
21

Array items length can be controlled with minItems and maxItems:

{
  "type": "array",
  "minItems": 5,
  "maxItems": 10,
  "items": {
    "type": "number"
  }
}
[
  71856238.93752578,
  -9957501.746244192,
  -7145041.207682312,
  -53358509.39871331,
  -83770088.68054512,
  -25448017.578881666,
  45764879.26211512,
  -5112859.453620076,
  -74878171.17192386,
  46948099.995764345
]

Faker.js and Chance methods

You can use the name of a faker.js or Chance method using the x-faker or x-chance properties:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "x-chance": "company"
    },
    "description": {
      "type": "string",
      "x-faker": "company.catchPhrase"
    }
  }
}
{
  "name": "Citigroup, Inc",
  "description": "Vision-oriented foreground middleware"
}

You can pass parameters to the method using an object with the method name as a key and an array of values as parameters:

{
  "type": "object",
  "properties": {
    "date": {
      "type": "string",
      "format": "date",
      "x-faker": {
        "date.between": ["2000", "2050"]
      }
    }
  }
}
{
  "date": "2040-05-06"
}

You can pass also object as a single parameter:

{
  "type": "object",
  "properties": {
    "email": {
      "type": "string",
      "format": "email",
      "x-chance": {
        "email": {
          "domain": "acme.com"
        }
      }
    }
  }
}
{
  "email": "[email protected]"
}

For Faker.js, you can interpolate multiple results with the fake method:

{
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "x-faker": {
        "fake": ["{{name.lastName}}, {{name.firstName}} {{name.suffix}}"]
      }
    }
  }
}
{
  "name": "Schmeler, Odie Jr."
}

The code generation is based on json-schema-faker, you can also check the project documentation for other examples.

License

MIT