New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

openapi-mock-generator

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

openapi-mock-generator

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.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

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": "aci@acme.com"
}

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

FAQs

Package last updated on 25 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc