krs

koa-router-swagger

# Feature

Showing:

Popularity

Downloads/wk

3

Maintenance

No Maintenance Data Available

Package

Dependencies

15

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

koa-router-swagger

Feature

  • parse swagger doc file to koa router
  • support parameters form valid (incomplete)
  • support redis cache
  • built-in swagger ui

Install

npm install koa-router-swagger --save

Quick Start

let koa = require('koa');
let bodyParser = require('koa-bodyparser');
let koaSwaggerRouter = require('koa-router-swagger');

let app = koa();

app.use(bodyParser());

let opt = {
  apiDoc: './api/api.yaml',
  controllerDir: './controller',
  redis: redisClient,
  port: 9000
}

let swagger = new koaSwaggerRouter(app, opt);
app.use(swagger.routes());
app.use(swagger.apiExplorer());

app.listen(9000)
  • apiDoc: the swagger doc file, support json and yaml
  • controllerDir: the controller dir in the apiDoc
  • redis: a redis client, like ioredis
  • port: koa server listen port, for open the api explorer

Extended word of the swagger spec

x-controller

It's an array of middleware. the order represent to the handle follow.

  • file: middleware file
  • handler: middleware in file
paths:
  /:
    get:
      description: 'Index'
      x-controller:
        - file: user
          handler: isLogin
        - file: page
          handler: userPage

x-cache

It's base on koa-router-cache.

  • expire: time to live, ms
paths:
  /test:
    get:
      description: 'Index'
      x-cache:
          expire: 10000

Swagger Doc explorer

open http://127.0.0.1:9000/api-explorer

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100