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

openapi2html

v1.1.22

Published

Yet another static html generator for Open API 2.0 / Swagger 2.0

Downloads

1,361

Readme

openapi2html

Yet another static html generator for Open API 2.0 / Swagger 2.0. It generates Bootstrap 4 compatible static html from your Swagger API spec. Not all the Swagger features are supported -- if you miss anything, let me know.

main workflow Coverage Status dependencies Status Maintainability node code style License Status

Install

npm install openapi2html

Usage

First, use swagger-parser to parse your api from json or yaml. Then, use openapi2html to generate html, e.g.:

const parser = require('swagger-parser');
const openapi2html = require('openapi2html');

...
const api = await parser.parse('my-api.yaml');
const html = openapi2html(api);

Options

openapi2html may take a second parameter for options, e.g.:

...
const options = {
  tagColors: {
    pet: 'primary',
    store: 'warning',
    user: 'success'
  },
  show: {
    host: false
  }
};
const html = openapi2html(api, options);

There are the following options:

  • tagColors maps your operations' tags to Bootstrap theme colors primary, secondary, success, danger, warning, info, light, dark. Please do not use danger because this is already used for deprecated. The default theme color is secondary. If you use custom colors, you need to provide the according CSS classes, e.g., badge-mycolor. Hex color values are not supported.
  • show is used for switching on or off certain information. The following is supported: version (default true), host (default true), basePath (default true), contact (default false), license (default false), termsOfService (default false), schemes (default true), consumes (default true), produces (default true)

Styling

The generated html doesn't provide any styling. It is plain Bootstrap 4 compatible html, i.e., it uses <h1> through <h6>, <code>, <a>, as well as Bootstrap's Card and Badge components. In addition, there are classes o2h-* attached such as o2h-operation-get to allow some customized styling.

This is what worked for me:

<html>
<head>
  ...
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
  <style>
    .card {
      margin-bottom: 1rem;
    }
    .h2, h2 {
      margin-top: 1rem;
    }
    .h4, h4 {
      margin-top: .5rem;
    }
    .card .card-body .h4, .card .card-body h4 {
      border-top: 1px solid #eee;
      margin-top: 1rem;
      padding-top: 1rem;
    }
    .card .card-body .h5, .card .card-body h5 {
      margin-top: 1rem;
    }
    .o2h-description p {
      color: grey;
      margin-bottom: .5rem;
    }
    .card .card-body .o2h-description p {
      margin-bottom: 0;
    }
    .card .card-body .o2h-example pre {
      background-color: #eee;
    }
    .o2h-parameter h5 .badge {
      font-size: small;
    }
  </style>
</head>
<body>
  <div class="container">
    <!-- include api html here -->
  </div>
</body>
</html>