Socket
Socket
Sign inDemoInstall

swagger-tools

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-tools - npm Package Compare versions

Comparing version 0.6.10 to 0.6.11

109

lib/specs.js

@@ -107,2 +107,9 @@ /*

var validateArrayType = function validateArrayType (data, path, dest) {
// We have to do this manually for now (https://github.com/swagger-api/swagger-spec/issues/174)
if (data.type === 'array' && _.isUndefined(data.items)) {
createErrorOrWarning('OBJECT_MISSING_REQUIRED_PROPERTY', 'Missing required property: items', data, path, dest);
}
};
// TODO: Move this to a helper

@@ -115,13 +122,17 @@

// Validate the value type/format
try {
validators.validateTypeAndFormat(parameter.name, val,
parameter.type === 'array' ? parameter.items.type : parameter.type,
parameter.type === 'array' && parameter.items.format ?
parameter.items.format :
parameter.format);
} catch (err) {
// TODO: Update to notify of 'INVALID_FORMAT'
createErrorOrWarning ('INVALID_TYPE', err.message, val, path, dest);
return;
validateArrayType(parameter, path, dest);
// Validate the value type/format (Skip for array since we manually handle it above for now)
if (parameter.type === 'array' && !_.isUndefined(parameter.items)) {
try {
validators.validateTypeAndFormat(parameter.name, val,
parameter.type === 'array' ? parameter.items.type : parameter.type,
parameter.type === 'array' && parameter.items.format ?
parameter.items.format :
parameter.format);
} catch (err) {
// TODO: Update to notify of 'INVALID_FORMAT'
createErrorOrWarning ('INVALID_TYPE', err.message, val, path, dest);
return;
}
}

@@ -166,13 +177,17 @@

// Validate the value type/format
try {
validators.validateTypeAndFormat(parameter.name, val,
parameter.type === 'array' ? parameter.items.type : parameter.type,
parameter.type === 'array' && parameter.items.format ?
parameter.items.format :
parameter.format);
} catch (err) {
// TODO: Update to notify of 'INVALID_FORMAT'
createErrorOrWarning('INVALID_TYPE', err.message, val, path, dest);
return;
validateArrayType(parameter, path, dest);
// Validate the value type/format (Skip for array since we manually handle it above for now)
if (parameter.type === 'array' && !_.isUndefined(parameter.items)) {
try {
validators.validateTypeAndFormat(parameter.name, val,
parameter.type === 'array' ? parameter.items.type : parameter.type,
parameter.type === 'array' && parameter.items.format ?
parameter.items.format :
parameter.format);
} catch (err) {
// TODO: Update to notify of 'INVALID_FORMAT'
createErrorOrWarning('INVALID_TYPE', err.message, val, path, dest);
return;
}
}

@@ -400,6 +415,8 @@

validateArrayType(property, pPath, results.error);
// Keep track of the model references
if (property.$ref) {
getModelMetadata(modelsMetadata, property.$ref).refs.push(pPath.concat(['$ref']));
} else if (property.type === 'array' && property.items.$ref) {
} else if (property.type === 'array' && !_.isUndefined(property.items) && !_.isUndefined(property.items.$ref)) {
getModelMetadata(modelsMetadata, property.items.$ref).refs.push(pPath.concat(['items', '$ref']));

@@ -456,3 +473,5 @@ }

} else if (model.type === 'array') {
if (model.items.$ref) {
validateArrayType(model, path, results.errors);
if (!_.isUndefined(model.items) && !_.isUndefined(model.items.$ref)) {
if (!isRemoteRef(model.items.$ref)) {

@@ -462,3 +481,4 @@ getModelMetadata(modelsMetadata,

}
} else if (!_.isUndefined(model.items.type) && spec.primitives.indexOf(model.items.type) === -1) {
} else if (!_.isUndefined(model.items) && !_.isUndefined(model.items.type) &&
spec.primitives.indexOf(model.items.type) === -1) {
_.each(model.items, function (item, index) {

@@ -481,8 +501,10 @@ var sPath = path.concat('items', index.toString());

} else if (property.type === 'array') {
if (property.items.$ref) {
if (!isRemoteRef(property.items.$ref)) {
getModelMetadata(modelsMetadata,
refToJsonPointer(property.items.$ref)).refs.push(pPath.concat(['items', '$ref']));
}
} else if (!_.isUndefined(property.items.type) && spec.primitives.indexOf(property.items.type) === -1) {
validateArrayType(property, pPath, results.errors);
if (!_.isUndefined(property.items) && !_.isUndefined(property.items.$ref) &&
!isRemoteRef(property.items.$ref)) {
getModelMetadata(modelsMetadata,
refToJsonPointer(property.items.$ref)).refs.push(pPath.concat(['items', '$ref']));
} else if (!_.isUndefined(property.items) && !_.isUndefined(property.items.type) &&
spec.primitives.indexOf(property.items.type) === -1) {
_.each(property.items, function (schema, index) {

@@ -498,3 +520,3 @@ var sPath = pPath.concat('items', index.toString());

// Add self reference to all model definitions outside of #/definitions (They are inline models or references)
if (toJsonPointer(path).indexOf('#/definitions/') === -1) {
if (path.length > 3 || toJsonPointer(path).indexOf('#/definitions/') === -1) {
metadata.refs.push(path);

@@ -871,7 +893,12 @@ }

_.reduce(operation.parameters, function (seenParameters, parameter, index) {
var pPath = oPath.concat('parameters', index.toString());
validateArrayType(parameter, pPath, result.errors);
// Add model references from parameter type/items
if (spec.primitives.indexOf(parameter.type) === -1) {
addModelRef(parameter.type, oPath.concat(['parameters', index.toString(), 'type']));
} else if (parameter.type === 'array' && parameter.items.$ref) {
addModelRef(parameter.items.$ref, oPath.concat(['parameters', index.toString(), 'items', '$ref']));
} else if (parameter.type === 'array' && !_.isUndefined(parameter.items) &&
!_.isUndefined(parameter.items.$ref)) {
addModelRef(parameter.items.$ref, pPath.concat(['items', '$ref']));
}

@@ -881,3 +908,3 @@

validateNoExist(seenParameters, parameter.name, 'OPERATION_PARAMETER', 'Operation parameter',
oPath.concat('parameters', index.toString(), 'name'), result.errors);
pPath.concat('name'), result.errors);

@@ -889,3 +916,3 @@ // Keep track of path parameters

'API path parameter could not be resolved: ' + parameter.name, parameter.name,
oPath.concat('parameters', index.toString(), 'name'), result.errors);
pPath.concat('name'), result.errors);
}

@@ -929,4 +956,6 @@

validateArrayType(operation, oPath, result.errors);
// Add model references from type/items
if (operation.type === 'array' && operation.items.$ref) {
if (operation.type === 'array' && !_.isUndefined(operation.items) && !_.isUndefined(operation.items.$ref)) {
addModelRef(operation.items.$ref, oPath.concat(['items', '$ref']));

@@ -1107,7 +1136,7 @@ } else if (spec.primitives.indexOf(operation.type) === -1) {

// Find models defined/referenced in #/paths/{path}/{method}/responses
_.each(operation.responses, function (response, responseCode) {
_.each(operation.responses, function (responseObj, responseCode) {
var rPath = oPath.concat('responses', responseCode);
if (!_.isUndefined(response.schema)) {
processModel(spec, modelsMetadata, response.schema, toJsonPointer(rPath.concat('schema')),
if (!_.isUndefined(responseObj.schema)) {
processModel(spec, modelsMetadata, responseObj.schema, toJsonPointer(rPath.concat('schema')),
rPath.concat('schema'), response);

@@ -1114,0 +1143,0 @@ }

{
"name": "swagger-tools",
"version": "0.6.10",
"version": "0.6.11",
"description": "Various tools for using and integrating with Swagger.",

@@ -5,0 +5,0 @@ "main": "index.js",

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