koa-router-joi-swagger
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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 And koa2-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',
            ...: ...
          },
        },
      },
    },
  })
);

/koa-router-joi-swagger/

    Package Sidebar

    Install

    npm i koa-router-joi-swagger

    Weekly Downloads

    0

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    20.8 kB

    Total Files

    9

    Last publish

    Collaborators

    • vaso991