0.0.0 • Published 3 years ago

@dylan92/sardine v0.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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 url
  • port mock sever port
  • requestMiddlewares & responseMiddleWares middleware use in koa mock server, more about koa

Swagger Schemes

📖 : Swagger Schemes V2

💡: 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 use minimum & maximum

  • string types use maxLength & minLength

  • array types use maxItems & minItems

  • enum types use for options

  • default value use for fake value

TODO

  • swagger v3 support
  • request validtor middleware(options 😄)