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

hapi-swagger

Package Overview
Dependencies
Maintainers
2
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 14.1.3 to 14.2.0

6

index.d.ts

@@ -374,2 +374,8 @@ import { Plugin } from '@hapi/hapi';

validatorUrl?: string;
/**
* Controls whether the "Try it out" section should be enabled by default
* @default false
*/
tryItOutEnabled?: string;
}

@@ -376,0 +382,0 @@ }

11

lib/builder.js

@@ -95,3 +95,3 @@ const Hoek = require('@hapi/hoek');

if (request.query.tags) {
let filterTags = request.query.tags.split(',');
const filterTags = request.query.tags.split(',');
routes = Filter.byTags(filterTags, routes);

@@ -103,4 +103,4 @@ }

let paths = new Paths(settings);
let pathData = paths.build(routes);
const paths = new Paths(settings);
const pathData = paths.build(routes);
out.paths = pathData.paths;

@@ -218,3 +218,3 @@ out.definitions = pathData.definitions;

internals.removeNoneSchemaOptions = function(options) {
let out = Hoek.clone(options);
const out = Hoek.clone(options);
[

@@ -252,3 +252,4 @@ 'debug',

'routeTag',
'validate'
'validate',
'tryItOutEnabled',
].forEach(element => {

@@ -255,0 +256,0 @@ delete out[element];

@@ -31,3 +31,4 @@ const { resolve } = require('path');

acceptToProduce: true, // internal, NOT public
pathReplacements: []
pathReplacements: [],
tryItOutEnabled: false,
};

@@ -34,3 +34,3 @@ const Hoek = require('@hapi/hoek');

// find existing definition by this definitionName
let foundDefinition = currentCollection[definitionName];
const foundDefinition = currentCollection[definitionName];
if (foundDefinition) {

@@ -135,3 +135,3 @@ // deep compare objects

if (Utilities.startsWith(key, nextModelNamePrefix)) {
let num = parseInt(key.replace(nextModelNamePrefix, ''), 10) || 0;
const num = parseInt(key.replace(nextModelNamePrefix, ''), 10) || 0;
if (num && num > highest) {

@@ -155,6 +155,6 @@ highest = num;

let key;
let hash = internals.hash(definition);
const hash = internals.hash(definition);
for (key in currentCollection) {
let obj = currentCollection[key];
const obj = currentCollection[key];

@@ -161,0 +161,0 @@ if (hash === internals.hash(obj)) {

@@ -16,6 +16,6 @@ const Utilities = require('../lib/utilities');

group.appendGroupByPath = function(pathPrefixSize, basePath, routes, pathReplacements) {
let out = [];
const out = [];
routes.forEach(route => {
let prefix = group.getNameByPath(pathPrefixSize, basePath, route.path, pathReplacements);
const prefix = group.getNameByPath(pathPrefixSize, basePath, route.path, pathReplacements);
// append tag reference to route

@@ -46,7 +46,7 @@ route.group = [prefix];

let i = 0;
let pathHead = [];
let parts = path.split('/');
const pathHead = [];
const parts = path.split('/');
while (parts.length > 0) {
let item = parts.shift();
const item = parts.shift();

@@ -53,0 +53,0 @@ if (item !== '') {

@@ -79,3 +79,4 @@ const Hoek = require('@hapi/hoek');

validator: Joi.object()
})
}),
tryItOutEnabled: Joi.boolean(),
}).unknown();

@@ -100,3 +101,3 @@

const validateOption = { validate: options.validate }
let settings = Hoek.applyToDefaults(Defaults, options, { nullOverride: true });
const settings = Hoek.applyToDefaults(Defaults, options, { nullOverride: true });
const publicDirPath = Path.resolve(__dirname, '..', 'public');

@@ -313,3 +314,3 @@

plugin.ext('onPostHandler', (request, h) => {
let response = request.response;
const response = request.response;
// if the reply is a view add settings data into template system

@@ -362,3 +363,3 @@ if (response.variety === 'view') {

const appendQueryString = function (url, qsName, qsValue) {
let urlObj = Url.parse(url);
const urlObj = Url.parse(url);
if (qsName && qsValue) {

@@ -365,0 +366,0 @@ urlObj.query = Querystring.parse(qsName + '=' + qsValue);

@@ -40,5 +40,5 @@ const Hoek = require('@hapi/hoek');

info.build = function(options) {
var out = options.info ? Hoek.applyToDefaults(info.defaults, options.info) : info.defaults;
const out = options.info ? Hoek.applyToDefaults(info.defaults, options.info) : info.defaults;
Joi.assert(out, info.schema);
return out;
};

@@ -46,3 +46,3 @@ const Hoek = require('@hapi/hoek');

parameters.fromProperties = function(schemaObj, parameterType) {
let out = [];
const out = [];
// if (this.allowedParameterTypes.indexOf(parameterType) === -1) {

@@ -92,3 +92,3 @@ // return out;

keys.forEach((element, index) => {
let key = keys[index];
const key = keys[index];
let item = schemaObj.properties[key];

@@ -109,3 +109,3 @@ item.name = key;

this.replaceObjectsWithStrings(item);
item = this.removePropsRecursively(item);

@@ -112,0 +112,0 @@ out.push(item);

@@ -49,10 +49,10 @@ const Hoek = require('@hapi/hoek');

internals.paths.prototype.build = function(routes) {
let self = this;
const self = this;
let routesData = [];
const routesData = [];
// loop each route
routes.forEach(route => {
let routeOptions = Hoek.reach(route, 'settings.plugins.hapi-swagger') || {};
let routeData = {
const routeOptions = Hoek.reach(route, 'settings.plugins.hapi-swagger') || {};
const routeData = {
path: route.path,

@@ -130,3 +130,3 @@ method: route.method.toUpperCase(),

['GET', 'POST', 'PUT', 'PATCH', 'DELETE'].forEach(method => {
var newRoute = Hoek.clone(routeData);
const newRoute = Hoek.clone(routeData);
newRoute.method = method.toUpperCase();

@@ -151,9 +151,9 @@ routesData.push(newRoute);

internals.paths.prototype.buildRoutes = function(routes) {
let self = this;
let pathObj = {};
let swagger = {
const self = this;
const pathObj = {};
const swagger = {
definitions: {},
'x-alt-definitions': {}
};
let definitionCache = [new WeakMap(), new WeakMap()];
const definitionCache = [new WeakMap(), new WeakMap()];

@@ -165,5 +165,5 @@ // reset properties

routes.forEach(route => {
let method = route.method;
const method = route.method;
let path = internals.removeBasePath(route.path, this.settings.basePath, this.settings.pathReplacements);
let out = {
const out = {
summary: route.description,

@@ -200,7 +200,7 @@ operationId: route.id || Utilities.createId(route.method, path),

// set from plugin options or from route options
let payloadType = internals.overload(this.settings.payloadType, route.payloadType);
const payloadType = internals.overload(this.settings.payloadType, route.payloadType);
// build payload either with JSON or form input
let payloadStructures = this.getDefaultStructures();
let payloadJoi = internals.getJOIObj(route, 'payloadParams');
const payloadJoi = internals.getJOIObj(route, 'payloadParams');
if (payloadType.toLowerCase() === 'json') {

@@ -229,5 +229,5 @@ // set as json

// set required true/false for each path params
//var pathParams = this.properties.toParameters (internals.getJOIObj(route, 'pathParams'), 'path', false);
//const pathParams = this.properties.toParameters (internals.getJOIObj(route, 'pathParams'), 'path', false);
let pathStructures = this.getDefaultStructures();
let pathJoi = internals.getJOIObj(route, 'pathParams');
const pathJoi = internals.getJOIObj(route, 'pathParams');
if (Utilities.hasJoiChildren(pathJoi)) {

@@ -266,5 +266,5 @@ pathStructures = this.getSwaggerStructures(pathJoi, 'path', false, false);

//let headerParams = this.properties.toParameters (internals.getJOIObj(route, 'headerParams'), 'header', false);
//const headerParams = this.properties.toParameters (internals.getJOIObj(route, 'headerParams'), 'header', false);
let headerStructures = this.getDefaultStructures();
let headerJoi = internals.getJOIObj(route, 'headerParams');
const headerJoi = internals.getJOIObj(route, 'headerParams');
if (Utilities.hasJoiChildren(headerJoi)) {

@@ -289,3 +289,3 @@ headerStructures = this.getSwaggerStructures(headerJoi, 'header', false, false);

let queryStructures = this.getDefaultStructures();
let queryJoi = internals.getJOIObj(route, 'queryParams');
const queryJoi = internals.getJOIObj(route, 'queryParams');
if (Utilities.hasJoiChildren(queryJoi)) {

@@ -309,3 +309,3 @@ queryStructures = this.getSwaggerStructures(queryJoi, 'query', false, false);

//let name = out.operationId + method;
//const name = out.operationId + method;
//userDefindedSchemas, defaultSchema, statusSchemas, useDefinitions, isAlt

@@ -342,3 +342,3 @@ out.responses = this.responses.build(route.responses, route.responseSchema, route.responseStatus, true, false);

internals.getJOIObj = function(route, name) {
let prama = route[name];
const prama = route[name];
// if (Utilities.hasJoiChildren(route[name])) {

@@ -435,3 +435,3 @@ // prama = route[name]._inner.children;

}
let out = {
const out = {
properties: outProperties || {},

@@ -438,0 +438,0 @@ parameters: outParameters || []

@@ -85,4 +85,7 @@ const Hoek = require('@hapi/hoek');

// get name from joi label if its not a path
if (!name && Utilities.geJoiLabel(joiObj) && parameterType !== 'path') {
name = Utilities.geJoiLabel(joiObj);
if (!name && parameterType !== 'path') {
const joiLabel = Utilities.getJoiLabel(joiObj);
if (joiLabel) {
name = joiLabel;
}
}

@@ -96,3 +99,3 @@

}
let map = this.propertyMap[joiType];
const map = this.propertyMap[joiType];
property.type = map.type;

@@ -116,3 +119,3 @@ if (map.format) {

// add enum
let describe = joiObj.describe();
const describe = joiObj.describe();
const allowDropdown = !property['x-meta'] || !property['x-meta'].disableDropdown;

@@ -130,3 +133,3 @@ if (allowDropdown && Array.isArray(describe.allow) && describe.allow.length) {

// filter out empty values and arrays
var enums = describe.allow.filter(item => {
const enums = describe.allow.filter(item => {
return item !== '' && item !== null;

@@ -159,3 +162,3 @@ });

if (useDefinitions === true) {
let refName = this.definitions.append(name, property, this.getDefinitionCollection(isAlt), this.settings);
const refName = this.definitions.append(name, property, this.getDefinitionCollection(isAlt), this.settings);
property = {

@@ -166,3 +169,3 @@ $ref: this.getDefinitionRef(isAlt) + refName

} else if (joiObj.$_terms.patterns) {
let objectPattern = joiObj.$_terms.patterns[0];
const objectPattern = joiObj.$_terms.patterns[0];
let patternName = 'string';

@@ -189,4 +192,4 @@ if (objectPattern.schema) {

if (useDefinitions === true) {
let objectSchema = { type: 'object', properties: {} };
let refName = this.definitions.append(name, objectSchema, this.getDefinitionCollection(isAlt), this.settings);
const objectSchema = { type: 'object', properties: {} };
const refName = this.definitions.append(name, objectSchema, this.getDefinitionCollection(isAlt), this.settings);
property = {

@@ -209,3 +212,3 @@ $ref: this.getDefinitionRef(isAlt) + refName

if (useDefinitions === true) {
let refName = this.definitions.append(name, property, this.getDefinitionCollection(isAlt), this.settings);
const refName = this.definitions.append(name, property, this.getDefinitionCollection(isAlt), this.settings);
property = {

@@ -254,3 +257,3 @@ $ref: this.getDefinitionRef(isAlt) + refName

internals.convertRules(property, describe.rules, ['unit'], 'x-format');
let exampleObj = Hoek.reach(joiObj, '$_terms.examples.0');
const exampleObj = Hoek.reach(joiObj, '$_terms.examples.0');
/* $lab:coverage:off$ */

@@ -422,9 +425,9 @@ // exampleObj.value != null will coerce undefined and null

joiObj._ids._byKey.forEach(obj => {
let keyName = obj.id;
const keyName = obj.id;
let itemName = obj.id;
let joiChildObj = obj.schema;
const joiChildObj = obj.schema;
// get name form label if set
if (Utilities.geJoiLabel(joiChildObj)) {
itemName = Utilities.geJoiLabel(joiChildObj);
if (Utilities.getJoiLabel(joiChildObj)) {
itemName = Utilities.getJoiLabel(joiChildObj);
}

@@ -488,4 +491,4 @@ //name, joiObj, parent, parameterType, useDefinitions, isAlt

// swagger appears to only support one array item type at a time, so grab the first one
let arrayItemTypes = joiObj.$_terms.items;
let arrayItem = Utilities.first(arrayItemTypes);
const arrayItemTypes = joiObj.$_terms.items;
const arrayItem = Utilities.first(arrayItemTypes);

@@ -495,12 +498,12 @@ if (arrayItem) {

let itemName;
if (Utilities.geJoiLabel(arrayItem)) {
itemName = Utilities.geJoiLabel(arrayItem);
if (Utilities.getJoiLabel(arrayItem)) {
itemName = Utilities.getJoiLabel(arrayItem);
}
//name, joiObj, parent, parameterType, useDefinitions, isAlt
let arrayItemProperty = this.parseProperty(itemName, arrayItem, property, parameterType, useDefinitions, isAlt);
const arrayItemProperty = this.parseProperty(itemName, arrayItem, property, parameterType, useDefinitions, isAlt);
if (this.simpleTypePropertyMap[arrayItem.type.toLowerCase()]) {
// map simple types directly
property.items = {};
for (let key in arrayItemProperty) {
for (const key in arrayItemProperty) {
property.items[key] = arrayItemProperty[key];

@@ -531,4 +534,4 @@ }

// add first into definitionCollection
let child = joiObj.$_terms.matches[0].schema;
let childName = Utilities.geJoiLabel(joiObj);
const child = joiObj.$_terms.matches[0].schema;
const childName = Utilities.getJoiLabel(joiObj);
//name, joiObj, parent, parameterType, useDefinitions, isAlt

@@ -540,6 +543,6 @@ property = this.parseProperty(childName, child, property, parameterType, useDefinitions, false);

if (this.settings.xProperties === true) {
let altArray = joiObj.$_terms.matches
const altArray = joiObj.$_terms.matches
.map(obj => {
let childMetaName = Utilities.getJoiMetaProperty(obj.schema, 'swaggerLabel');
let altName = childMetaName || Utilities.geJoiLabel(obj.schema) || name;
const childMetaName = Utilities.getJoiMetaProperty(obj.schema, 'swaggerLabel');
const altName = childMetaName || Utilities.getJoiLabel(obj.schema) || name;

@@ -557,5 +560,5 @@ //name, joiObj, parent, parameterType, useDefinitions, isAlt

// add first into definitionCollection
let child = joiObj.$_terms.matches[0].then;
let childMetaName = Utilities.getJoiMetaProperty(child, 'swaggerLabel');
let childName = childMetaName || Utilities.geJoiLabel(child) || name;
const child = joiObj.$_terms.matches[0].then;
const childMetaName = Utilities.getJoiMetaProperty(child, 'swaggerLabel');
const childName = childMetaName || Utilities.getJoiLabel(child) || name;
//name, joiObj, parent, parameterType, useDefinitions, isAlt

@@ -566,3 +569,3 @@ property = this.parseProperty(childName, child, property, parameterType, useDefinitions, false);

if (property && this.settings.xProperties === true) {
let altArray = joiObj.$_terms.matches
const altArray = joiObj.$_terms.matches
.reduce((res, obj) => {

@@ -574,4 +577,4 @@ obj.then && res.push(obj.then);

.map(joiNewObj => {
let childMetaName = Utilities.getJoiMetaProperty(joiNewObj, 'swaggerLabel');
let altName = childMetaName || Utilities.geJoiLabel(joiNewObj) || name;
const childMetaName = Utilities.getJoiMetaProperty(joiNewObj, 'swaggerLabel');
const altName = childMetaName || Utilities.getJoiLabel(joiNewObj) || name;
return this.parseProperty(altName, joiNewObj, property, parameterType, useDefinitions, true);

@@ -584,4 +587,4 @@ })

//if (!property.$ref && Utilities.geJoiLabel(joiObj)) {
// property.name = Utilities.geJoiLabel(joiObj);
//if (!property.$ref && Utilities.getJoiLabel(joiObj)) {
// property.name = Utilities.getJoiLabel(joiObj);
//}

@@ -588,0 +591,0 @@

@@ -50,5 +50,5 @@ const HTTPStatus = require('http-status');

if (Utilities.hasProperties(statusSchemas)) {
for (let key in statusSchemas) {
for (const key in statusSchemas) {
// name, joiObj, parameterType, useDefinitions, isAlt
let response = this.getResponse(key, statusSchemas[key], null, useDefinitions, isAlt);
const response = this.getResponse(key, statusSchemas[key], null, useDefinitions, isAlt);
out[key] = response;

@@ -93,3 +93,3 @@ }

internals.responses.prototype.optionOverride = function(discoveredSchemas, userDefindedSchemas, useDefinitions, isAlt) {
for (let key in userDefindedSchemas) {
for (const key in userDefindedSchemas) {
// create a new object by cloning - dont modify user definded objects

@@ -117,3 +117,3 @@ let out = Hoek.clone(userDefindedSchemas[key]);

for (let item in out) {
for (const item in out) {
const value = out[item];

@@ -143,3 +143,3 @@

//name, joiObj, parent, parameterType, useDefinitions, isAlt
let outProperties = this.properties.parseProperty(null, joiObj, null, 'body', useDefinitions, false);
const outProperties = this.properties.parseProperty(null, joiObj, null, 'body', useDefinitions, false);
out = {

@@ -146,0 +146,0 @@ description: Hoek.reach(joiObj, '_flags.description'),

@@ -73,4 +73,3 @@ const Hoek = require('@hapi/hoek');

utilities.hasProperties = function(obj) {
let key;
for (key in obj) {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {

@@ -90,4 +89,3 @@ return true;

utilities.deleteEmptyProperties = function(obj) {
let key;
for (key in obj) {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {

@@ -132,3 +130,3 @@ // delete properties undefined values

utilities.sortFirstItem = function(array, firstItem) {
let out = array;
let out = array; // todo does this corrupt the array?
if (firstItem) {

@@ -172,3 +170,3 @@ out = [firstItem];

utilities.hasKey = function(obj, findKey) {
for (var key in obj) {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {

@@ -197,3 +195,3 @@ if (typeof obj[key] === 'object') {

utilities.findAndRenameKey = function(obj, findKey, replaceKey) {
for (var key in obj) {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {

@@ -223,3 +221,3 @@ if (typeof obj[key] === 'object') {

utilities.removeProps = function(obj, listOfProps) {
for (let key in obj) {
for (const key in obj) {
if (Object.prototype.hasOwnProperty.call(obj, key)) {

@@ -254,4 +252,4 @@ if (listOfProps.indexOf(key) === -1 && this.startsWith(key, 'x-') === false) {

let byId = Hoek.reach(joiObj, '_ids._byId')
let byKey = Hoek.reach(joiObj, '_ids._byKey')
const byId = Hoek.reach(joiObj, '_ids._byId')
const byKey = Hoek.reach(joiObj, '_ids._byKey')

@@ -301,3 +299,3 @@ if (byId.size > 0) { return true }

*/
utilities.geJoiLabel = function(joiObj) {
utilities.getJoiLabel = function(joiObj) {
// old version

@@ -340,5 +338,5 @@ /* $lab:coverage:off$ */

/* $lab:coverage:off$ */
var makeCompareFunction = function(f, direction) {
const makeCompareFunction = function(f, direction) {
if (typeof f !== 'function') {
var prop = f;
const prop = f;
// make unary function

@@ -351,3 +349,3 @@ f = function(v1) {

// f is a unary function mapping a single item to its sort score
var uf = f;
const uf = f;
f = function(v1, v2) {

@@ -365,3 +363,3 @@ return uf(v1) < uf(v2) ? -1 : uf(v1) > uf(v2) ? 1 : 0;

/* mixin for the `thenBy` property */
var extend = function(f, d) {
const extend = function(f, d) {
f = makeCompareFunction(f, d);

@@ -375,4 +373,4 @@ f.thenBy = tb;

returns a new compare function, which has a `thenBy` method as well */
var tb = function(y, d) {
var self = this;
const tb = function(y, d) {
const self = this;
y = makeCompareFunction(y, d);

@@ -397,4 +395,4 @@ return extend(function(a, b) {

if (path.indexOf('/') > -1) {
let items = path.split('/');
items = items.map(function(item) {
const pathItems = path.split('/');
const items = pathItems.map(function(item) {
// replace chars such as '{'

@@ -401,0 +399,0 @@ item = item.replace(/[^\w\s]/gi, '');

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

@@ -51,3 +51,3 @@ "repository": {

"@hapi/hoek": "^9.0.2",
"handlebars": "^4.5.3",
"handlebars": "^4.7.7",
"http-status": "^1.0.1",

@@ -54,0 +54,0 @@ "json-schema-ref-parser": "^6.1.0",

@@ -6,2 +6,3 @@ # hapi-swagger

[![Maintainers Wanted](https://img.shields.io/badge/maintainers-wanted-red.svg?style=for-the-badge)](https://github.com/glennjones/hapi-swagger/issues/718)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/glennjones/hapi-swagger/Node.js%20CI?style=for-the-badge)

@@ -8,0 +9,0 @@ [![npm downloads](https://img.shields.io/npm/dm/hapi-swagger.svg?style=for-the-badge)](https://www.npmjs.com/package/hapi-swagger)

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