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

swagger-service-skeleton

v1.3.0

Published

Rapid service-skeleton/prototyping solution for NodeJS/Swagger based Microservices.

Downloads

18

Readme

swagger-service-skeleton

Build Status Prod Dependencies Dev Dependencies Coverage Status npm version

Stats Downloads

NPM package for rapidly spinning up REST service skeletons.

Minimal Example

The example below shows the minimal, happy-path configuration:

'use strict';
const skeleton = require('swagger-service-skeleton');
const instance = skeleton({
    ioc: {
        autoRegister: { pattern: './services/*.js', 
                        rootDirectory: __dirname },
    },
    codegen: {
        templateSettings: {
            implementationPath: '../../../src/controllers',
        },
        temporaryDirectory: './dist/codegen',
    },
    service: {
        swagger: './contracts/your-service-api.yaml',
    }
});
module.exports = instance;

Calling instance() will start up a complete service on port 10010 serving your swagger-API. It expects that controller-implementations are located in ./src/controllers relative to your application root path.

Complete Configuration

The example below shows a complete-configuration for using the library, with typical defaults specified. The only required parameters are the ones in the minimal example above.

'use strict';
const skeleton = require('swagger-service-skeleton');
const yamljs = require('yamljs');

const instance = skeleton({
    // IOC Settings - See swagger-service-skeleton on NPM for more parameters
    ioc: {
        // Automatically register services with the IoC Container
        autoRegister: {
            pattern: './services/*.js',
            rootDirectory: __dirname,
        },

        // Optional base IoC container for this middleware.
        // Otherwise will default to a require('somersault')() container.
        rootContainer: null,
    },

    // Custom middleware to run
    customMiddleware: {
        // Middleware to run after some essentials/setup
        // but before the swagger-router.
        beforeSwagger: [
            (req, res, next) => {
              /* do something */
              next();  
            },
        ],
        // Middleware to run after filtering, but immediately before the controller
        beforeController: [
            (err, req, res, next) => {
                /* Do something */
                next();
            },
        ],
        // Middleware to run after swagger-router, if the
        // request does not get handled by swagger (i.e.
        // custom error handling)
        afterSwagger: [
            (err, req, res, next) => {
                /* Do something */
                next();
            },
        ]
    },

    // Code generation 
    codegen: {
        // swagger-codegen compliant template-set to use.
        // Defaults to require('swagger-template-es6-server')
        templateSet: null,

        // Template-set specific settings, passed to template-set
        // constructor.
        templateSettings: {
            // Path to implemented controllers. This is specific
            // to your templateSet though.
            implementationPath: '../../../src/controllers',
        },

        // Where swagger-codegen writes controller stubs to
        // Defaults to ./termp
        temporaryDirectory: './dist/codegen',

        // Path relative to temporaryDirectory where we can
        // find swagger-tools compliant controllers. Typically
        // this is 'controllers' or similar.
        controllerStubFolder: 'controllers'
    },

    // Redirection rules, executed before requests in lexicographic
    // order.
    redirects: {
        // Label
        'documentation-from-root': {
            // Regex to match for req.url
            match: /^\/$/,
            
            // Destination path
            target: '/docs',
        },
    },

    // Service 
    service: {
        // Your service contract. Can be a .yaml file name
        // or a pre-parsed file. Will load text from file
        // using require('yamljs')
        swagger: './contracts/your-service.yaml',

        // Port to listen on
        listenPort: 10010
    }
});
module.exports = instance;

See Also

The following projects are useful reading:

- swagger-codegen
    - Code generation using handlebars templates for swagger
      API contracts.
- gulp-swagger-codgen
    - Leverages swagger-codegen and templatesets to produce
      code output. This module does the same, but on the fly
      when starting up to a temporary directory.
- somersault
    - IoC for Node.js projects, with support for ES6 classes,
      arrow functions, static objects and regular functions.
- connect-ioc
    - Leverages somersault to provide per-request IoC support.