1.2.3 • Published 9 years ago
koa-router-swagger v1.2.3
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 --saveQuick 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: userPagex-cache
It's base on koa-router-cache.
- expire: time to live, ms
paths:
/test:
get:
description: 'Index'
x-cache:
expire: 10000Swagger Doc explorer
open http://127.0.0.1:9000/api-explorer1.2.3
9 years ago
1.2.2
9 years ago
2.1.4
9 years ago
2.1.3
9 years ago
2.1.2
9 years ago
2.1.1
9 years ago
2.1.0
9 years ago
2.0.4
9 years ago
2.0.3
9 years ago
2.0.2
9 years ago
1.2.1
9 years ago
2.0.1
9 years ago
1.2.0
9 years ago
2.0.0
9 years ago
1.1.9
9 years ago
1.1.8
9 years ago
1.1.7
9 years ago
1.1.6
9 years ago
1.1.5
10 years ago
1.1.4
10 years ago
1.1.3
10 years ago
1.1.2
10 years ago
1.1.1
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago
0.1.0
10 years ago