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.

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 });
await server.register({
plugin: HapiSwagger,
options: { ... },
});
await server.register({
plugin: HapiSwaggerStatic,
options: { ... },
});
await server.start();
};
provision();
Options
The plugin provides the following options:
path | /documentation.html | The endpoint providing the static documentation page. |
swaggerEndpoint | /swagger.json | The endpoint to read the Swagger API specification from. |
cache | { privacy: 'public', expiresIn: 60 * 60 * 1000 } // one hour | Hapi'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. |