npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mlshv/modern-koa-docs

v3.0.2

Published

An automatic documentation generator for koa.js APIs

Downloads

2

Readme

modern-koa-docs

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


npm version project depencies Known Vulnerabilities MIT open issues last commit


Information about original project

This project is fork of koa-docs

TODO: rewrite docs

Index

Demo

See example folder for source code. View example output

Screenshot

Install

npm install --save modern-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('/docs', {
   title: 'Pet Store API',
   version: '1.0.0',

   theme: 'simplex',    // Specify a theme from www.bootswatch.com;
                        // default is un-themed bootstrap

   routeHandlers: 'disabled',  // Hide the route implementation code from docs

   groups: [
      { 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/docs`);
});

docs.get(path, options)

Creates a koa middleware which generates and serves api documentation using the specs provided in the options object.

Arguments

  1. path (String): the GET path at which the documentation will be served
  2. options (Object)
    • title: string representing the page title; displayed at the top of the docs
    • version: string representing api version; also displayed at top of the docs
    • routeHandlers: string indicating whether to show the route handler code in the docs. Options are disabled, expanded or collapsed (collapsed is the default)
    • theme: string name of a theme from bootswatch to be used as the default theme
    • groups: array of group specs as described below

Returns

(GeneratorFunction): Middleware suitable for use in koa.js app

Group specs

Groups are used to logically display the various sections of your api. They are declared as follows:

  • groupName: string representing the name of the group
  • description: string that describes the group; 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 group is being displayed in an expanded state. Make this as long as you need.
  • prefix: optional string to be prefixed to all route paths in this group
  • routes: array of route specs representing the routes in this group. See below for details on route specs.

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
    • multipartOptions: body for multipart, 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 / Contribution

Please feel free to claim any of the following features for development; more features can be requested by opening an issue.

  • [ ] Create separate section for models (joi objects that have a label)
  • [ ] Add popovers for displaying models
  • [ ] Quick filter (fuzzysearch)
  • [ ] Ability to save the generated HTML to file
  • [ ] E2E testing of output

License

MIT