koa-router-joi-swagger
v1.0.0
Published
> Validate router input and generate swagger ui based on router and validation
Downloads
2
Readme
koa-router-joi-swagger
Validate router input and generate swagger ui based on router and validation
Installation
$ npm install koa-router-joi-swagger
Uses
Joi
,@koa/router
Andkoa2-swagger-ui
Usage
Import Packages
const Koa = require('koa');
const { Router, Validator, Joi, Swagger } = require('koa-router-joi-swagger');
const app = new Koa();
const router = new Router();
Validate Input (See Joi Documentation)
router.post(
'/api/:param1',
Validator({
query: {
queryParam: Joi.string().required(),
},
body: {
bodyParam: Joi.number().optional(),
},
params: {
param1: Joi.string().required(),
},
})
);
Serve Swagger Docs (pass koa2-swagger-ui config as uiConfig
)
router.get(
'/docs',
Swagger({
// Pass router as parameter
router,
uiConfig: {
routePrefix: false,
swaggerOptions: {
spec: {
info: {
title: 'Test Api',
version: '1.0.0',
description: 'This is test api specs',
...: ...
},
},
},
},
})
);