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 🙏

© 2026 – Pkg Stats / Ryan Hefner

openapi-support

v0.0.11

Published

utility for loading and parsing swagger

Readme

ibm-openapi-support

This module is a utility to make the process of loading and parsing documents in the OpenAPI (swagger) format a simple task. The primary use case for this is code generation where a swagger document is loaded, parsed and then relavent data structures for building api endpoints are made available.

Quick start

Swaggerize contains two modules, index.js and utils.js. They are described below:

  • utils.loadAsync: This utility method is used for loading a swagger document from a file path or url. The method takes two arguments and returns a dictionary with two keys, loaded and parsed. The loaded key contains a javascript object containing the original document. The parsed key contains the a dictionary with parsed swagger elements. The arguments to loadAsync:
    • path or url to the openApi document.
    • in-memory filesystem object; only required if loading from a file path.
var swaggerize = require('ibm-openapi-support')
var loadedApi
var parsedSwagger

var memFs = require('mem-fs')
var editor = require('mem-fs-editor')
var store = memFs.create()
var fs = editor.create(store)

return utils.loadAsync('../resources/person_dino.json', fs)
  .then(loaded => swaggerize.parse(loaded, formatters))
  .then(response => {
    loadedApi = response.loaded
    parsedSwagger = response.parsed
  })
  • index.parse: This method is used to parse the swagger document and build a dictionary of structures that contain the routes, resources and basepath required for generating API code. The parse method will use the supplied formatters to modify the path and the resource. This method takes two parameters:
    • stringified OpenApi (swagger) document.
    • formatters dictionary: This contains formatters for the path pathFormatter and for the resource resourceFormatter The formatters take a path parameter and return a string.

The data returned takes the following format:

{ basepath: string,
  resources: { "resourceName": [ {  method: string, // method is one of: "post",
                                                    //                   "put",
                                                    //                   "delete",
                                                    //                   "get",
                                                    //                   "patch"
                                    route: string, // path to register
                                    params: [ { model: string, // model name
                                                array: boolean, // is this an array? }
                                    ],
                                    responses: [ { model: string, // model name
                                                   array: boolean, // is this an array? }
                                    ]
                                 }
                               ]
             },
  models: [ models declarations ]
}
var swaggerize = require('ibm-openapi-support')
var swaggerizeUtils = require('ibm-openapi-support/utils')

var swaggerDocument = 'your OpenApi (swagger) document goes here' 

function reformatPathToNodeExpress (thepath) {
  // take a swagger path and convert the parameters to express format.
  // i.e. convert "/path/to/{param1}/{param2}" to "/path/to/:param1/:param2"
  var newPath = thepath.replace(/{/g, ':')
  return newPath.replace(/}/g, '')
}

function resourceNameFromPath (thePath) {
  // grab the first valid element of a path (or partial path) and return it.
  return thePath.match(/^\/*([^/]+)/)[1]
}

this.parsedSwagger = undefined;
var formatters = {
  'pathFormatter': helpers.reformatPathToNodeExpress,
  'resourceFormatter': helpers.resourceNameFromPath
}

if (swaggerDocument !== undefined) {
  return swaggerize.parse(swaggerDocument, formatters)
  .then(response => {
    this.loadedApi = response.loaded
    this.parsedSwagger = response.parsed
  })
  .catch(err => {
    err.message = 'failed to parse document ' + err.message
    throw err
  })
}

if (this.parsedSwagger) {
  Object.keys(this.parsedSwagger.resources).forEach(function(resource) {
    var context = {
      'resource': resource,
      'routes': this.parsedSwagger.resources[resource],
      'basepath': this.parsedSwagger.basepath,
      'models': this.parsedSwagger.models
    }
    this.fs.copyTpl(this.templatePath('fromswagger/routers/router.js'), this.destinationPath(`server/routers/${resource}.js`), context)
    this.fs.copyTpl(this.templatePath('test/resource.js'), this.destinationPath(`test/${resource}.js`), context)
  }.bind(this))
}