New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 7.2.0 to 7.3.0

examples/basic.js

2

examples/jwt.js

@@ -53,3 +53,3 @@ 'use strict';

host: 'localhost',
port: 8000
port: 3000
});

@@ -56,0 +56,0 @@

@@ -71,5 +71,6 @@ 'use strict';

let connection = request.connection;
let namedConnection = null;
if (settings.connectionLabel) {
connection = request.server.select(settings.connectionLabel).connections[0];
connection = namedConnection = request.server.select(settings.connectionLabel).connections[0];
if (request.server.select(settings.connectionLabel).connections.length === 1) {

@@ -81,3 +82,3 @@ request.server.log(['error'], 'connectionLabel should only define one connection to document');

// collect root information
builder.default.host = internals.getHost(request, connection);
builder.default.host = internals.getHost(request, namedConnection);
builder.default.schemes = [internals.getSchema(request, connection)];

@@ -156,13 +157,23 @@

* @param {Object} request
* @param {Object} connection
* @param {Object} namedConnection
* @return {String}
*/
internals.getHost = function (request, connection) {
internals.getHost = function (request, namedConnection) {
const matches = request.headers.host.match(/^[^:]*/);
let host = matches[0];
const port = connection.info.port;
// Use the request host with the connection's port
const hostname = `${host}:${port}`;
return request.headers['x-forwarded-host'] || request.headers['disguised-host'] || hostname;
let host = request.headers.host;
// use namedConnection when hapi is set to use hapi-swagger on one connection and the api on another
if (namedConnection) {
host = namedConnection.info.host;
const port = namedConnection.info.port;
const protocol = namedConnection.info.protocol;
// do not set port if its protocol http/https with default post numbers
// this cannot be tested on most desktops as ports below 1024 throw EACCES
/* $lab:coverage:off$ */
if (port && (protocol === 'http' && port !== 80) || (protocol === 'https' && port !== 443)) {
host += ':' + port;
}
/* $lab:coverage:on$ */
}
return request.headers['x-forwarded-host'] || request.headers['disguised-host'] || host;
};

@@ -169,0 +180,0 @@

@@ -71,2 +71,5 @@ 'use strict';

let foundDefinitionName;
delete definition.optional;
// find definitionName by matching hash of object

@@ -73,0 +76,0 @@ if (settings.reuseModels) {

@@ -89,2 +89,6 @@ 'use strict';

let joiType = joiObj._type.toLowerCase();
// for Joi extension, use the any type
if (!(joiType in this.propertyMap)){
joiType = 'any';
}
let map = this.propertyMap[joiType];

@@ -132,2 +136,7 @@ property.type = map.type;

// add date properties
if (property.type === 'string' && property.format === 'date') {
property = this.parseDate(property, joiObj);
}
// add object child properties

@@ -336,2 +345,20 @@ if (property.type === 'object') {

/**
* parse date property
*
* @param {Object} property
* @param {Object} joiObj
* @return {Object}
*/
internals.properties.prototype.parseDate = function (property, joiObj) {
if (joiObj._flags.timestamp) {
property.type = 'number';
delete property.format;
}
return property;
};
/**
* parse object property

@@ -338,0 +365,0 @@ *

@@ -9,2 +9,3 @@ # 7.2.0 Options Reference

* `auth`: (boolean, string or object) defines security strategy to use for plugin resouces - default: `false`,
* `connectionLabel`: (string) A label used to document an API on a different HAPI server connection

@@ -11,0 +12,0 @@

{
"name": "hapi-swagger",
"description": "A swagger documentation UI generator plugin for hapi",
"version": "7.2.0",
"version": "7.3.0",
"author": "Glenn Jones",

@@ -44,2 +44,3 @@ "repository": {

"hapi-auth-jwt2": "^7.0.1",
"hapi-auth-basic": "^4.2.0",
"inert": "^4.0.1",

@@ -46,0 +47,0 @@ "js2xmlparser": "^1.0.0",

@@ -15,3 +15,2 @@ 'use strict';

lab.experiment('connections', () => {

@@ -18,0 +17,0 @@

@@ -193,2 +193,46 @@ 'use strict';

lab.test('test that optional array is not in swagger output', (done) => {
let testRoutes = [{
method: 'POST',
path: '/server/1/',
config: {
handler: Helper.defaultHandler,
tags: ['api'],
validate: {
payload: Joi.object({
a: Joi.number().required(),
b: Joi.string().optional()
}).label('test')
}
}
}];
Helper.createServer({}, testRoutes, (err, server) => {
server.inject({ method: 'GET', url: '/swagger.json' }, function (response) {
expect(err).to.equal(null);
expect(response.statusCode).to.equal(200);
expect(response.result.definitions.test).to.equal({
'type': 'object',
'properties': {
'a': {
'type': 'number'
},
'b': {
'type': 'string'
}
},
'required': [
'a'
]
});
done();
});
});
});
});

@@ -216,2 +216,10 @@ 'use strict';

lab.test('parse type date timestamp', (done) => {
clearDown();
expect(propertiesNoAlt.parseProperty('x', Joi.date().timestamp(), null, 'body', true, false)).to.equal({ 'type': 'number' });
done();
});
lab.test('parse type number', (done) => {

@@ -461,1 +469,15 @@

});
lab.experiment('joi extension - ', () => {
lab.test('custom joi extension', (done) => {
clearDown();
const extension = Joi.extend({
base: Joi.string(),
name: 'custom'
});
expect(propertiesNoAlt.parseProperty('x', extension.custom(), null, 'body', true, false)).to.equal({ 'type': 'string' });
done();
});
});

@@ -505,2 +505,3 @@ # 7.2.0 Usage Guide

* __`payload: function (value, options, next) {next(null, value);}`__ The use of custom functions to validate pramaters is not support beyond replacing them with an emtpy model call "Hidden Model".
* __`Joi.date().format('yy-mm-dd')` __ The use of a `moment` pattern to format a date cannot be reproduced in Swagger

@@ -507,0 +508,0 @@

Sorry, the diff of this file is not supported yet

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