1.2.3 • Published 7 years ago

koa-router-swagger v1.2.3

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

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
1.2.3

7 years ago

1.2.2

7 years ago

2.1.4

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

1.2.1

7 years ago

2.0.1

7 years ago

1.2.0

7 years ago

2.0.0

7 years ago

1.1.9

7 years ago

1.1.8

8 years ago

1.1.7

8 years ago

1.1.6

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.0

8 years ago