Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.49 KB

README.md

File metadata and controls

57 lines (42 loc) · 1.49 KB

koa-swagger-mock

build build download

NPM

Introduce

It's a middleware for swagger-mock!

preview this project, do this!

git clone https://github.com/ShanaMaid/koa-swagger-mock

npm install

npm run test

url: localhost:3000/api/pet/1212121212

Usage

npm install koa-swagger-mock -save

Example

const Koa = require('koa');
const app = new Koa();
const KoaSwaggerMock = require('../lib/koa-swagger-mock');
const path = require('path');
const fs = require('fs');


const swagger = JSON.parse(
  fs.readFileSync(path.resolve(__dirname, '../json/example.json'), {encoding: 'utf8'})
);

const koaSwagMock = KoaSwaggerMock({
  swagger,
  prefix: '/api'
});

app.use(koaSwagMock.routes());
app.listen(3000);

this is mock resp!

http://localhost:3000/api/pet/findByStatus mock resp

API

KoaSwaggerMock({...params})

  • swagger - (Object) - (required) - api can be one of the following.

    • A Swagger JSON Object.
  • prefix - (String) - (optional) - url prefix.

    • default is ''