New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

hapi-swagger-static

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-swagger-static

A small companion plugin for ´hapi-swagger´ providing a static html documentation page as hapi route

2.0.0-alpha.3
Version published
Weekly downloads
204
-9.33%
Maintainers
1
Weekly downloads
 
Created

hapi-swagger-static

Plugin for Hapi v17 providing a static html documentation page. It's a small companion plugin for hapi-swagger or hapi-swaggered to create a static page from the /swagger.json endpoint. The static page is provided as route /documentation.html (can be renamed). It supports most of Swagger 2.0 / Open API 2.0.

build status Coverage Status Dependency Status Greenkeeper badge Maintainability FOSSA Status node code style License Status

Install

npm install --save hapi-swagger-static

Usage

Register the plugin with Hapi server like this:

const Hapi = require('hapi');
const HapiSwagger = require('hapi-swagger');
const HapiSwaggerStatic = require('hapi-swagger-static');
const Inert = require('inert');
const Vision = require('vision');

const server = new Hapi.Server({
  port: 3000,
});

const provision = async () => {
  await server.register({ plugin: Inert });
  await server.register({ plugin: Vision });
  // first, add your api routes to hapi
  await server.register({ // second, register `hapi-swagger` plugin
    plugin: HapiSwagger,
    options: { ... },
  });
  await server.register({ // last, register this plugin
    plugin: HapiSwaggerStatic,
    options: { ... },
  });
  await server.start();
};

provision();

Options

The plugin provides the following options:

OptionDefaultDescription
 path /documentation.html The endpoint providing the static documentation page.
swaggerEndpoint/swagger.jsonThe endpoint to read the Swagger API specification from.
cache{ privacy: 'public', expiresIn: 60 * 60 * 1000 } // one hourHapi's route.options.cache to be assigned to the static documentation endpoint. Please refer to the Hapi docs for more information.
auth-Hapi's route.options.auth to be assigned to the static documentation endpoint. Please refer to the Hapi docs for more information. By default, this option is not set, i.e., inheriting auth settings from Hapi's server.options.routes.auth.
headers{}The request's authorization header is automatically forwarded to the /swagger.json endpoint. If you need any additional headers, add them through the headers option.

FAQs

Package last updated on 04 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts