docmoc
Documentation and Mock API Server for Swagger
Features
- One port (changeable)
- Respond random mock data
- Respond specified mock data
- Respond a specified length mock array
- Validate API request based on Swagger
Install
npm i -g docmoc
or yarn global add docmoc
Run
docmoc [options] [swagger_file_path]
Options
-p, --port <port> Change port
-h, --help output usage information
Swagger Custom Properties
x-mock
String|Number|Boolean|Array
If you set x-mock
property, the API will respond a specified value in JSON.
# swagger.yml type: objectproperties: foo: type: string x-mock: FOO bar: type: string
If you set an array to x-mock
property, the API will respond a randomly sampled value in JSON.
# swagger.yml type: objectproperties: foo: type: integer x-mock: - 123 - 456 - 789 bar: type: integer
x-mock-array-size
Integer
If you set x-mock-array-size
property, the API will respond an array that has specified length elements.
# swagger.yml type: arrayitems: type: object properties: name: type: string age: type: integer minimum: 18 maximum: 99x-mock-array-size: 3
x-mock-array-key
String
If you set x-mock-array-key
property, the API will respond a value in x-mock-array-size
that is specified at the key.
# swagger.yml type: objectproperties: total: type: integer x-mock-array-key: users users: type: array items: type: object properties: name: type: string age: type: integer minimum: 18 maximum: 99 x-mock-array-size: 3