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

stag

v0.1.0

Published

Generate Swagger documentation, statically

Downloads

4

Readme

stag

The stag Node module provides a JavaScript API and a command line tool for generating static documentation from Swagger API metadata.

See the issues for more info, and comment on one or file an issue if you have suggestions.

Command Line Usage

First, install stag via npm:

npm install -g stag

Next, write a simple Django-style template:

<!DOCTYPE html>
<title>{{ info.title }}</title>
<h1>{{ info.title }} / version {{ apiVersion }}</h1>

Then, point it at a Swagger API URL and your template:

stag http://petstore.swagger.wordnik.com/api/api-docs/ template.html

This will produce:

<!DOCTYPE html>
<title>Swagger Sample App</title>
<h1>Swagger Sample App / version 1.0.0</h1>

Check out the examples for more usage tips, or just run stag --help:

Swagger static generator version 0.1.0:

  stag [ options ] <url> [ <template> [ <output> ] ]

  <url> is a Swagger-compliant JSON URL, e.g.
    http://petstore.swagger.wordnik.com/api/api-docs

  <template> is either:
    1. a relative filename,
    2. a template name in one of the template paths indicated by one or more -p
       or --path options, or
    3. empty, "-" or "/dev/stdin" to read the template from stdin

  <output> is an optional filename to which the rendered template should be
    written, or a directory to which multiple files should be written if
    --dir is specified. If left off, the output will be written to stdout.

Examples:

  Use only positional arguments:
  $ swagger-static $API_URL template.html output.html

  Produce output on stdout and redirect to a file:
  $ swagger-static $API_URL template.html > output.html

  Provide the template on stdin, output on stdout:
  $ echo "{{ swaggerVersion }}" | swagger-static $API_URL


Options:
  -d, --dir         process <template> as a directory of files                  
  -p, --path        add this directory to the list of template paths            
  -a, --autoescape  auto-escape HTML in template tags                           
  -E, --enhanced    indicates that the Swagger JSON is already 'enhanced'       
  -e, --encoding    when reading the template from stdin, use this encoding
                    (default: 'utf8')                                           
  -v                print the version number and exit                           

Background

At 18F we're building Swagger-compliant APIs to make them more accessible and facilitate simpler, dynamically generated documentation for API users. Unfortunately, the only generally accepted way of exposing human-readable Swagger API documentation is SwaggerUI, a client-side JavaScript library with some non-trivial shortcomings:

  1. Because all SwaggerUI-based documentation is rendered at runtime, search engines are [theoretically] unable to crawl their contents.
  2. Tight coupling with jQuery and a long list of dependencies means that you've got to include everything they include, or it just won't run.
  3. Tight coupling between the distributed JavaScript source and HTML, e.g. lots of hard-coded CSS selectors means that it's a huge pain to customize the output.
  4. Unweildy and largely redundant stylesheets, which are tricky to override and impractical to rewrite.

My plan was (and is) to make a suite of tools and templates that faciliate the generation of static, human-readable documentation to replace SwaggerUI. Check out the issues to see where I am and provide feedback.