Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 2 additions & 119 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,122 +1,5 @@
# hapi-swagger-next
# hapi-swagger-next-tmp

> A fork of the excellent [hapi-swagger](https://github.com/glennjones/hapi-swagger) module that delivers the latest version of the Swagger UI

This is a [OpenAPI (aka Swagger)](https://openapis.org/) plug-in for [HAPI](http://hapijs.com/) When installed it will self document the API interface
in a project.

[![build status](https://img.shields.io/travis/glennjones/hapi-swagger.svg?style=flat-square)](https://travis-ci.org/darahayes/hapi-swagger.svg?branch=master)
[![Coverage Status](https://img.shields.io/coveralls/glennjones/hapi-swagger/dev.svg?style=flat-square)](https://coveralls.io/r/darahayes/hapi-swagger)
[![npm downloads](https://img.shields.io/npm/dm/hapi-swagger.svg?style=flat-square)](https://www.npmjs.com/package/hapi-swagger-next)
[![MIT license](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://raw.github.com/glennjones/microformat-shic/master/license.txt)

__Review [release notes for v7.0.0](https://github.com/glennjones/hapi-swagger/issues/325)__


# Install

You can add the module to your HAPI using npm:

$ npm install 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.
DO NOT INSTALL - Package is fork of `hapi-swagger-next` waiting for this PR to be merged -> https://github.com/darahayes/hapi-swagger/pull/1.


5 changes: 3 additions & 2 deletions lib/paths.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict';
const Hoek = require('hoek');
const Joi = require('joi');
const fastSafeStringify = require('fast-safe-stringify');

const Parameters = require('../lib/parameters');
const Definitions = require('../lib/definitions');
const Properties = require('../lib/properties');
const Responses = require('../lib/responses');
const Utilities = require('../lib/utilities');


const internals = {};

exports = module.exports = internals.paths = function (settings) {
Expand Down Expand Up @@ -385,8 +387,7 @@ internals.overload = function (base, priority) {
* @return {Boolean}
*/
internals.hasFileType = function (route) {

let routeString = JSON.stringify(route);
let routeString = fastSafeStringify(route);
return routeString.indexOf('swaggerType') > -1;
};

Expand Down
Loading