Mock data generator CLI for Swagger3 (OpenAPI 3)
Clone or download
yayoc Merge pull request #5 from yayoc/greenkeeper/openapi3-ts-1.0.0
Update openapi3-ts to the latest version 🚀
Latest commit f6bef41 Sep 21, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
__tests__ Rename parse with fileParse Jun 24, 2018
src Support example property Jun 27, 2018
.gitignore Change export dir Jun 24, 2018
.npmignore Add .npmignore Jun 25, 2018
.travis.yml Add .travis file Jun 24, 2018
README.md docs(readme): add Greenkeeper badge Jun 27, 2018
package-lock.json 0.1.8 Jun 27, 2018
package.json fix(package): update openapi3-ts to version 1.0.0 Sep 4, 2018
tsconfig.json Change export dir Jun 24, 2018

README.md

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