mock data generator from Swagger (OpenAPI 3)
npm install swagger-to-mockMock data generator CLI for Swagger3 (OpenAPI 3)
``shell`
npm i -g swagger-to-mock
`shell`
swagger-to-mock
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. format
If there is no rule like , values should be below.
`yaml`
string: ""
number: 0
integer: 0
boolean: true
array: []
object: {}
If we pass an example YAML file
`yaml`
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
`json`
[
{
"name": "",
"tag": "",
"id": 0
}
]
Naming JSON file will follow the format below.
${API_PATH}_${HTTP_METHOD}_${RESPONSE_STATUS}.json
swagger-to-mock will follow rules based on OpenAPI 3 specification for each data type, If the example value is not specified.
If you specify oneOf or anyOf, The value should be at the top type.
- format
- Minimum and Maximum
- Multiples
- format
- pattern
value should be true or false`.
- Mixed-Type Arrays
- Array Length
- Free-Form Object