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

serviser-doc

v2.1.4

Published

automated API documentation module

Downloads

4

Readme

Build Status

This serviser plugin generates documentation (swagger-ui like frontend) for serviser Apps.
Here is how it works in few steps:

  • During service initialization, available Apps are fetched from AppManager
  • Open API (OAS) REST API specification is generated from static route definitions
  • For each App in AppManager, corresponding (additional) Doc http app (which serves the documentation frontend) is created and pushed into internal AppManager stack
  • As Doc http apps implement the same interface of generic http App object, the service initialization process continues as it would without any documentation being generated.

OpenAPI front-end screenshot

USAGE

  • Hook up the plugin into your application in your app's index.js file:
const config  = require('serviser-config');
const Service = require('serviser');

//service initialization stuff...
const service = new Service(config);

//...

//hook-up the plugin
require('serviser-doc');
  • Enable automatic Doc app generation in your service config.json5:
{
    apps: {
        appName: {
            // provide the doc configuration section for each app you want
            // the documentation to be generated for
            doc: {
                baseUrl: 'http://127.0.0.1:3000',
                listen: 3000,
                title: 'User API', //optional
                stopOnError: true, //optional
                //allows us to include hand-crafted API description for each version
                readme: { //optional
                    'v2.0': 'lib/routes/v2.0/README.md'
                }
            }
        }
    }
}

From what the docs are generated?

  • Router & Route definitions - more specifically desc & summary constructor options.
  • Validation schema definitions provided to the route.validate & route.respondsWith methods.
  • Supported request content-type(s) as defined via route.acceptsContentType
  • Custom Ajv keyword $desc which serviser provides, can be used to describe individual request/response data properties in user defined Route validation schemas.
    route.respondsWith({ //200 - OK response
        type: 'object',
        properties: {
            is_active: {
                type: 'boolean',
                $desc: 'Whether the user has been online within a period of last 7 days'
            }
        }
    });
    
    //
    route.validate({
        username: {type: 'string'}
    }, 'params');
  • Possible route error responses can be described also by the route.respondsWith method:
    route.respondsWith(RequestError);
    route.respondsWith(new RequestError({
        apiCode: 'tag.alreadyExists'
        message: 'Tag already exists'
    }));
    route.respondsWith(UnauthorizedError);

Also see serviser Error management