z0mt3c / hapi-swaggered-ui

An easy swagger-ui drop-in plugin for hapi (to be used with hapi-swaggered).
39 stars 31 forks source link

hapi-swaggered-ui

Easy swagger-ui (v3) drop-in plugin for hapi to be used with hapi-swaggered.

Supports hapi 17.x and up For earlier versions check hapi-swaggered-ui 2.x (current default/latest npm install hapi-swaggered --save)

Build Status js-standard-style npm downloads

Install

npm install hapi-swaggered-ui@next

Configuration

Example

Since hapi-swaggered exposes its plugin configuration hapi-swaggered-ui should find it's swagger endpoint automatically. In case you want to use hapi-swaggered-ui without hapi-swaggered (or the auto-detection doesn't work) you can manually set the swagger endpoint by the swaggerEndpoint option. In addition the page title can be changed through the option title.

await server.register([
  require('inert'),
  require('vision'),
  {
    plugin: require('hapi-swaggered-ui'),
    options: {
      title: 'Example API',
      path: '/docs',
      authorization: { // see above
        field: 'apiKey',
        scope: 'query', // header works as well
        // valuePrefix: 'bearer '// prefix incase
        defaultValue: 'demoKey',
        placeholder: 'Enter your apiKey here'
      },
      swaggerOptions: {} // see above
    }
  }
])

May have a look at the example listed at https://github.com/z0mt3c/hapi-swaggered