0.0.0 • Published 3 years ago
@dylan92/sardine v0.0.0
Sardine
is one step mock tool, via swagger v2
, chance
, koa
. It will check request
and return response
. You can set swagger format
property with chance method name to fake different types data~
Install
npm install sardine -D
//or
yarn add sardine -D
Usage
// mock.js
const {
default: Sardine,
chanceInstance,
responseBodyMiddleware // a middleware Examples
} = require('sardine')
new Sardine({
url: 'https://petstore.swagger.io/v2/swagger.json',
port: 9000,
})
Run node mock.js
to start your first sardine mock server
Options
:
interface SardineOptions {
url: string
port?: number
requestMiddlewares?: Middleware[]
responseMiddleWares?: Middleware[]
}
/* make it is possible to config your chanceInstance
*/
public chanceInstance: {
/**
* config chance fake count of arrays
*/
__DEFAULT_ARRAY_COUNT?: number
/**
* max stack size for nest object
*/
_MAX_NEST_STACK_SIZE?: number
} = chanceInstance
url
swagger json urlport
mock sever portrequestMiddlewares
&responseMiddleWares
middleware use in koa mock server, more about koa
Swagger Schemes
💡: Newton's 🍎
However, the format property is an open string-valued property, and can have any value to support documentation needs. Formats such as "email", "uuid", etc., can be used even though they are not defined by this specification
🚥 : Rules
number
types useminimum
&maximum
string
types usemaxLength
&minLength
array
types usemaxItems
&minItems
enum
types use foroptions
default
value use for fake value
TODO
- swagger v3 support
- request validtor middleware(options 😄)
0.0.0
3 years ago