🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

swaggerize-routes

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swaggerize-routes - npm Package Compare versions

Comparing version

to
1.0.2

17

lib/buildroutes.js

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

validator = validation(options);
routes = [];

@@ -29,3 +28,3 @@

utils.verbs.forEach(function (verb) {
var route, pathnames, operation;
var route, pathnames, operation, validators;

@@ -50,8 +49,18 @@ operation = def[verb];

validators = {};
if (def.parameters) {
def.parameters.forEach(function (parameter) {
validators[parameter.in + parameter.name] = parameter;
});
}
if (operation.parameters) {
operation.parameters.forEach(function (parameter) {
route.validators.push(validator.make(parameter));
validators[parameter.in + parameter.name] = parameter;
});
}
route.validators = validator.makeAll(validators, route);
pathnames = [];

@@ -115,4 +124,2 @@

Object.keys(definition).forEach(function (type) {
var scopes;
assert.ok(securityDefinitions[type], 'Unrecognized security definition (' + type + ')');

@@ -119,0 +126,0 @@

@@ -10,5 +10,27 @@ 'use strict';

module.exports = function validator(options) {
var schemas;
var schemas, types;
schemas = {};
types = {
file: enjoi({
type: 'object',
properties: {
value: {
type: 'string',
minLength: 0,
required: true
},
consumes: {
type: 'string',
pattern: /multipart\/form-data|application\/x-www-form-urlencoded/,
required: true
},
in: {
type: 'string',
pattern: /formData/,
required: true
}
}
})
};

@@ -27,3 +49,18 @@ schemas['#'] = options.api;

*/
make: function (parameter) {
makeAll: function (validators, route) {
var self = this;
return Object.keys(validators).map(function (k) {
var parameter = validators[k];
return self.make(parameter, route.consumes);
});
},
/**
* Creates a parameter validator.
* @param parameter
* @returns {Function}
*/
make: function (parameter, consumes) {
var schema, coerce, template;

@@ -35,3 +72,3 @@

coerce = coercion(parameter);
coerce = coercion(parameter, consumes);

@@ -48,7 +85,13 @@ template = {

if (parameter.in === 'body' && template.schema) {
schema = enjoi(template.schema, schemas);
if ((parameter.in === 'body' || parameter.in === 'formData') && template.schema) {
schema = enjoi(template.schema, {
subSchemas: schemas,
types: types
});
}
else {
schema = enjoi(template, schemas);
schema = enjoi(template, {
subSchemas: schemas,
types: types
});
}

@@ -65,3 +108,2 @@

coerce && data && (data = coerce(data));
schema.validate(data, function (error, result) {

@@ -125,3 +167,3 @@ if (error) {

*/
function coercion(parameter) {
function coercion(parameter, consumes) {
var fn;

@@ -168,2 +210,12 @@

break;
case 'file': {
fn = function (data) {
return {
value: data,
consumes: consumes,
in: parameter.in
};
};
break;
}
}

@@ -170,0 +222,0 @@

{
"name": "swaggerize-routes",
"version": "1.0.1",
"version": "1.0.2",
"author": "Trevor Livingston <trlivingston@paypal.com>",

@@ -19,3 +19,3 @@ "description": "Swagger based route building.",

"debuglog": "^1.0.1",
"enjoi": "^0.2.0"
"enjoi": "^1.0.0"
},

@@ -22,0 +22,0 @@ "devDependencies": {