# @reptilbud/hapi-swagger

> A swagger documentation UI generator plugin for hapi (based on glennjones work)

Latest version **2.1.0** (published 2018-05-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install @reptilbud/hapi-swagger
pnpm add @reptilbud/hapi-swagger
yarn add @reptilbud/hapi-swagger
bun add @reptilbud/hapi-swagger
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2018-05-07 |
| First published | 2017-06-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 8 |
| Unpacked size | 3.8 MB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sebastien Ritz |
| Maintainers | reptilbud |
| Keywords | api, docs, swagger, hapi, joi |

## Links

- npm: https://www.npmjs.com/package/@reptilbud/hapi-swagger
- Repository: https://github.com/reptilbud/hapi-swagger
- Homepage: https://github.com/reptilbud/hapi-swagger#readme
- Issues: https://github.com/reptilbud/hapi-swagger/issues
- npm.io page: https://npm.io/package/@reptilbud/hapi-swagger

## Dependencies (8)

- [joi](https://npm.io/package/joi.md) 11.0.2
- [boom](https://npm.io/package/boom.md) ^5.2.0
- [hoek](https://npm.io/package/hoek.md) ^4.2.0
- [handlebars](https://npm.io/package/handlebars.md) ^4.0.10
- [http-status](https://npm.io/package/http-status.md) ^1.0.1
- [swagger-parser](https://npm.io/package/swagger-parser.md) ^3.4.2
- [fast-safe-stringify](https://npm.io/package/fast-safe-stringify.md) ^1.2.0
- [json-schema-ref-parser](https://npm.io/package/json-schema-ref-parser.md) ^3.3.1

## Alternatives

- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads

## Recent versions

- 2.1.0 (latest) — 2018-05-07
- 2.0.0 — 2017-10-27
- 1.0.2 — 2017-10-02
- 1.0.1 — 2017-06-08
- 1.0.0 — 2017-06-08

## README

# hapi-swagger

This repository is a fork of the [hapi-swagger](https://github.com/glennjones/hapi-swagger) project developped by glennjones.

[![Build Status](https://travis-ci.org/reptilbud/hapi-swagger.svg?branch=master)](https://travis-ci.org/reptilbud/hapi-swagger)
[![Coverage Status](https://coveralls.io/repos/github/reptilbud/hapi-swagger/badge.svg?branch=master)](https://coveralls.io/github/reptilbud/hapi-swagger?branch=master)

# Install

You can add the module to your HAPI using npm:

    $ npm install @reptilbud/hapi-swagger --save

If you want to view the documentation from your API you will also need to install the `inert` and `vision` plugs-ins which support templates and static
content serving.

    $ npm install inert --save
    $ npm install vision --save

# Documentation

* [Options Reference](optionsreference.md)
* [Usage Guide](usageguide.md)


# Quick start

In your HAPI apps main JavaScript file add the following code to created a HAPI `server` object. You will also add the routes for you API as describe on hapijs.com site.


```Javascript
const Hapi = require('hapi');
const Inert = require('inert');
const Vision = require('vision');
const HapiSwagger = require('hapi-swagger');
const Pack = require('./package');

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

const options = {
    info: {
            'title': 'Test API Documentation',
            'version': Pack.version,
        }
    };

server.register([
    Inert,
    Vision,
    {
        'register': HapiSwagger,
        'options': options
    }], (err) => {
        server.start( (err) => {
           if (err) {
                console.log(err);
            } else {
                console.log('Server running at:', server.info.uri);
            }
        });
    });

server.route(Routes);
```

# Tagging your API routes
As a project may be a mixture of web pages and API endpoints you need to tag the routes you wish Swagger to
document. Simply add the `tags: ['api']` property to the route object for any endpoint you want documenting.

You can even specify more tags and then later generate tag-specific documentation. If you specify
`tags: ['api', 'foo']`, you can later use `/documentation?tags=foo` to load the documentation on the
HTML page (see next section).

```Javascript
{
    method: 'GET',
    path: '/todo/{id}/',
    config: {
        handler: handlers.getToDo,
        description: 'Get todo',
        notes: 'Returns a todo item by the id passed in the path',
        tags: ['api'], // ADD THIS TAG
        validate: {
            params: {
                id : Joi.number()
                        .required()
                        .description('the id for the todo item'),
            }
        }
    },
}
```

Once you have tagged your routes start the application. __The plugin adds a page into your site with the route `/documentation`__,
so the the full URL for the above options would be `http://localhost:3000/documentation`.



# Contributing

Read the [contributing guidelines](https://github.com/glennjones/hapi-swagger/blob/master/.github/CONTRIBUTING.md) for details.




# Thanks
I would like to thank all that have contributed to the project over the last couple of years. This is a hard project to maintain, getting HAPI to work with Swagger
is like putting a round plug in a square hole. Without the help of others it would not be possible.

---
_Source: https://npm.io/package/@reptilbud/hapi-swagger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
