Socket
Socket
Sign inDemoInstall

koa-docs

Package Overview
Dependencies
8
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    koa-docs

An automatic documentation generator for koa.js APIs


Version published
Weekly downloads
95
increased by120.93%
Maintainers
1
Install size
26.8 MB
Created
Weekly downloads
 

Readme

Source

koa-docs

An automatic documentation generator for koa APIs. The goal is to make documentation easy using route specs that may already exist.

Demo

See example folder for source code. View example output

Screenshot

Install

> npm install --save koa-docs

Usage:

const app = require('koa')();
const docs = require('koa-docs');

// Create a path for viewing the docs (only GET method is supported)
app.use(docs.get('/v1/docs', {
   title: 'Pet Store API',
   version: '1.0.0',

   groups: [
      // Provide the routes to the koa-api-docs for rendering
      { groupName: 'Pets', routes: [/*  ... route specs ...  */] },
      { groupName: 'Store', routes: [/*  ... route specs ...  */] }
   ]
}));

app.listen(3000, (err) => {
   if (err) throw err;
   console.log(`Docs are available at http://localhost:3000/v1/docs`);
});

Route specs

The route specs are the same as koa-joi-router, therefore, those routes can be used directly with koa-docs. Specifications are as follows:

  • method: required HTTP method like "get", "post", "put", etc
  • path: required string
  • validate
    • header: object which conforms to Joi validation
    • query: object which conforms to Joi validation
    • params: object which conforms to Joi validation
    • body: object which conforms to Joi validation
    • maxBody: max incoming body size for forms or json input
    • failure: HTTP response code to use when input validation fails. default 400
    • type: if validating the request body, this is required. either form, json or multipart
    • output: output validator object which conforms to Joi validation. if output is invalid, an HTTP 500 is returned
    • continueOnError: if validation fails, this flags determines if koa-joi-router should continue processing the middleware stack or stop and respond with an error immediately. useful when you want your route to handle the error response. default false
  • handler: required GeneratorFunction
  • meta: meta data about this route. koa-joi-router ignores this but stores it along with all other route data

meta

In addition to the above options, koa-docs looks for the following properties in the meta object of each route:

  • friendlyName: string which is used in the sidebar and route title; route path is used if this is not proivded
  • description: string that describes the routes; keep this short at about 1 scentence. This is displayed in both expanded and collapsed states as well as in tooltips. This should be a simple string; no markdown
  • extendedDescription: string that supports markdown and is displayed only in when a route is being displayed in an expanded state. Make this as long as you need.

sample routes

Roadmap to 1.0

  • Multi version support
  • Ability to collapse/expand routes and groups
  • Quick filter
  • Quickly switch themes and configurable default theme

License

MIT

Keywords

FAQs

Last updated on 10 Nov 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc