Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagger-to-mock

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-to-mock

mock data generator from Swagger (OpenAPI 3)

  • 0.1.12
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
decreased by-15.25%
Maintainers
1
Weekly downloads
 
Created
Source

swagger-to-mock travis-ci Greenkeeper badge

Mock data generator CLI for Swagger3 (OpenAPI 3)

Install

npm i -g swagger-to-mock

Generate mock data

swagger-to-mock <YOUR SWAGGER FILE>

will generate JSON file per each API response.
JSON data values should be example values on your swagger if you specified examples.
Otherwise, swagger-to-mock follows data type rules and generate arbitrary values.
If there is no rule like format, values should be below.

string: ""
number: 0
integer: 0
boolean: true
array: []
object: {}

Example

If we pass an example YAML file

responses:
  '200':
    description: pet response
    content:
      application/json:
        schema:
          type: array
          items:
            $ref: '#/components/schemas/Pet'

swagger-to-mock will generate file named pets_get_200.json and the body should be below

[
  {
    "name": "",
    "tag": "",
    "id": 0
  }
]

File Name

Naming JSON file will follow the format below. ${API_PATH}_${HTTP_METHOD}_${RESPONSE_STATUS}.json

Data Type Support [In Progress]

swagger-to-mock will follow rules based on OpenAPI 3 specification for each data type, If the example value is not specified.

Mixed Types

If you specify oneOf or anyOf, The value should be at the top type.

Numbers

  • format
  • Minimum and Maximum
  • Multiples

String

  • format
  • pattern

Boolean

value should be true or false.

Null

Arrays

  • Mixed-Type Arrays
  • Array Length

Objects

  • Free-Form Object

Files

Any Type

Keywords

FAQs

Package last updated on 22 Dec 2019

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