Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-swagger

Package Overview
Dependencies
Maintainers
1
Versions
163
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-swagger - npm Package Compare versions

Comparing version 0.5.2 to 0.5.3

77

lib/index.js

@@ -26,3 +26,6 @@

listing: true,
index: false
index: false,
customJSHandler: function(request, reply) {
reply('').type('application/javascript');
},
}

@@ -41,3 +44,6 @@ };

// append settings data in template context
internals.appendReplyContext( plugin, settings );
// add routing for documentation API endpoint ie /docs

@@ -55,3 +61,3 @@ plugin.route({

handler: function(request, reply) {
reply.file(Path.join(__dirname, '..', 'public/swaggerui', 'swagger.html'));
reply.view('swagger.html', {});
}

@@ -73,2 +79,12 @@ });

plugin.route({
method: 'GET',
path: settings.endpoint + '/custom.js',
config: {
auth:settings.auth,
},
handler: settings.customJSHandler,
});
// add routing for swaggerui library directory ie /docs/swaggerui

@@ -261,3 +277,3 @@ plugin.route({

if(settings.authorizations[strategie] && settings.authorizations[strategie].type){
routeData.authorizations[settings.authorizations[strategie].type] = settings.authorizations[strategie]
routeData.authorizations[settings.authorizations[strategie].type] = settings.authorizations[strategie]
}

@@ -299,3 +315,23 @@ });

if (settings.info) {
// schema for settings
// https://github.com/swagger-api/swagger-spec/blob/master/versions/1.2.md#513-info-object
var settingsSchema = Joi.object().keys({
title: Joi.string().required(),
description: Joi.string().required(),
termsOfServiceUrl: Joi.string().optional(),
contact: Joi.string().email().optional(),
license: Joi.string().optional(),
licenseUrl: Joi.string().optional()
});
Joi.validate(settings.info, settingsSchema, function (err, value) {
if(err && err.message){
console.log('error hapi-swagger - settings.info:', err.message)
}else{
swagger.info = settings.info;
}
});
}
while (x < i) {

@@ -341,2 +377,7 @@ var route = routes[x];

internals._getClassName = function(schema) {
return schema && schema._settings ?
schema._settings.className || schema._settings.typeName : undefined;
}
// build documentation API endpoint for each route group

@@ -424,4 +465,3 @@ internals.buildAPIInfo = function (settings, apiData, slug) {

var responseClassName = route.responseSchema && route.responseSchema._settings ?
route.responseSchema._settings.className || route.responseSchema._settings.typeName : undefined;
var responseClassName = internals._getClassName(route.responseSchema);

@@ -575,3 +615,3 @@ var responseProperty = internals.validatorToProperty(responseClassName || op.nickname + '_response',

if (property.type === 'object' && param._inner) {
var className = undefined;
var className = internals._getClassName(param);
var param = (param._inner.children) ? param._inner.children : param._inner

@@ -609,9 +649,9 @@ property.type = internals.validatorsToModelName(

'type': arrayProperty.type
};
};
}else{
property.items = {
'$ref': arrayProperty.type
};
};
}
}

@@ -697,3 +737,22 @@ }

// append settings data in template context
internals.appendReplyContext = function ( plugin, settings ) {
plugin.ext('onPostHandler', function (request, next) {
var response = request.response;
if (response.variety === 'view') {
if(!response.source.context){
response.source.context = {};
}
if(!response.source.context['hapiSwagger']){
response.source.context['hapiSwagger'] = {};
}
response.source.context['hapiSwagger'] = settings
}
return next();
});
};
exports._internals = internals;

2

package.json
{
"name": "hapi-swagger",
"description": "A swagger documentation UI generator plugin for hapi",
"version": "0.5.2",
"version": "0.5.3",
"author": "Glenn Jones",

@@ -6,0 +6,0 @@ "repository": {

@@ -72,23 +72,24 @@ # hapi-swagger

The doc directory and all the files in the URLs below are added by the plugin
The all the files in the URLs below are added by the plugin, but you must server the custom page as template using `reply.view()`.
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='/docs/swaggerui/css/highlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='/docs/swaggerui/css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<script src="/docs/swaggerui/lib/shred.bundle.js" type="text/javascript"></script>
<script src='/docs/swaggerui/lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='/docs/swaggerui/lib/jquery.slideto.min.js' type='text/javascript'></script>
<script src='/docs/swaggerui/lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='/docs/swaggerui/lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='/docs/swaggerui/lib/handlebars-1.0.0.js' type='text/javascript'></script>
<script src='/docs/swaggerui/lib/underscore-min.js' type='text/javascript'></script>
<script src='/docs/swaggerui/lib/backbone-min.js' type='text/javascript'></script>
<script src='/docs/swaggerui/lib/swagger.js' type='text/javascript'></script>
<script src='/docs/swaggerui/swagger-ui.js' type='text/javascript'></script>
<script src='/docs/swaggerui/lib/highlight.7.3.pack.js' type='text/javascript'></script>
<link href='{{hapiSwagger.endpoint}}/swaggerui/css/highlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='{{hapiSwagger.endpoint}}/swaggerui/css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/shred.bundle.js' 'type=text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/jquery-1.8.0.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/jquery.slideto.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/jquery.wiggle.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/handlebars-1.0.0.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/underscore-min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/backbone-min.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/swagger.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/swagger-ui.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/swaggerui/lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script src='{{hapiSwagger.endpoint}}/custom.js' type='text/javascript'></script>
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
url: window.location.protocol + '//' + window.location.host + '/docs',
url: window.location.protocol + '//' + window.location.host + '{{hapiSwagger.endpoint}}',
dom_id: "swagger-ui-container",

@@ -98,3 +99,6 @@ supportedSubmitMethods: ['get', 'post', 'put', 'delete'],

log("Loaded SwaggerUI")
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
$('pre code').each(function(i, e) {
hljs.highlightBlock(e)
});
$('.response_throbber').attr( 'src', '{{hapiSwagger.endpoint}}/swaggerui/images/throbber.gif' );
},

@@ -112,7 +116,7 @@ onFailure: function(data) {

url: window.location.protocol + '//' + window.location.host + '/docs',
url: window.location.protocol + '//' + window.location.host + '{{hapiSwagger.endpoint}}',
to:
url: window.location.protocol + '//' + window.location.host + '/docs?tags=foo,bar,baz',
url: window.location.protocol + '//' + window.location.host + '{{hapiSwagger.endpoint}}?tags=foo,bar,baz',

@@ -147,11 +151,18 @@ This will load all routes that have one or more of the given tags (`foo` or `bar` or `baz`). More complex use of tags include:

* apiVersion: the version of your API
* basePath: the base URL of the API i.e. 'http://localhost:3000'
* documentationPath: the path to the default documentation page - the default is: '/documentation',
* enableDocumentationPage: enable the display of the documentation page - the default is: true,
* endpoint: the JSON endpoint that descibes the API - the default is: '/docs'
* pathPrefixSize: selects what segment of the URL path is used to group endpoints - the default is: 1
* payloadType: weather accepts JSON or form parameters for payload - the default is: 'json'
* produces: an array of the output types from your API - the default is: ['application/json']
* authorizations: an object containing [swagger authorization objects](https://github.com/swagger-api/swagger-spec/blob/master/versions/1.2.md#515-authorization-object), the keys mapping to HAPI auth strategy names. No defaults are provided.
* `apiVersion`: string The version of your API
* `basePath`: string The base URL of the API i.e. `http://localhost:3000`
* `documentationPath`: string The path of the documentation page - default: `/documentation`,
* `enableDocumentationPage`: boolean Enable the the documentation page - default: `true`,
* `endpoint`: string the JSON endpoint that descibes the API - default: `/docs`
* `pathPrefixSize`: number Selects what segment of the URL path is used to group endpoints - default: `1`
* `payloadType`: string Weather accepts `json` or `form` parameters for payload - default: `json`
* `produces`: array The output types from your API - the default is: `['application/json']`
* `authorizations`: object Containing [swagger authorization objects](https://github.com/swagger-api/swagger-spec/blob/master/versions/1.2.md#515-authorization-object), the keys mapping to HAPI auth strategy names. No defaults are provided.
* `info`: a [swagger info object](https://github.com/swagger-api/swagger-spec/blob/master/versions/1.2.md#513-info-object) with metadata about the API.
* `title` string Required. The title of the application
* `description` string Required. A short description of the application
* `termsOfServiceUrl` string A URL to the Terms of Service of the API
* `contact` string An email to be used for API-related correspondence
* `license` string The license name used for the API
* `licenseUrl` string A URL to the license used for the API

@@ -158,0 +169,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc