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

swagger-schema

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-schema - npm Package Compare versions

Comparing version 0.5.0 to 0.6.0

test/environment.js

9

constants.js

@@ -21,2 +21,8 @@ /**

var allowMultiple = [
'query',
'header',
'path',
];
/**

@@ -26,3 +32,4 @@ * Expose utils.

exports.allowMultiple = allowMultiple;
exports.notModel = notModel;
exports.primitives = primitives;
exports.notModel = notModel;

@@ -12,2 +12,3 @@ /**

var jjv = require('jjv');
var lodash = require('lodash');

@@ -26,8 +27,21 @@ /**

options = lodash.defaults(options || {}, {
setup: true,
});
this.schema = jjv();
this.coerceSchema = jjv();
this.schemas = [this.schema, this.coerceSchema];
if (options.setup) this.setup();
}
Environment.prototype.setupValidation = function() {
Environment.prototype.setup = function() {
this.coerceSchema.addTypeCoercion('array', function(v) {
if (!Array.isArray(v)) {
return typeof v === 'undefined' ? [] : [v];
}
return v;
});
this.coerceSchema.addTypeCoercion('integer', function(v) {

@@ -55,2 +69,6 @@ if (typeof v === 'string' && v.match(/^\-?\d+$/)) {

Environment.prototype.setupValidation = function() {
console.log('Environment.setupValidation is deprecated');
};
Environment.prototype.validate = function(schema, data, options) {

@@ -64,7 +82,12 @@ options = options || {};

Environment.prototype.validateThrow = function(schema, data, message) {
var errors = this.schema.validate(schema, data);
Environment.prototype.validateThrow = function(schema, data, options) {
if (typeof options === 'string') {
options = { message: options };
}
options = options || {};
var errors = this.validate(schema, data, options);
if (errors) {
var err = new Error(message || 'Validation failed');
var err = new Error(options.message || 'Validation failed');
err.errors = errors;

@@ -71,0 +94,0 @@ err.message += '\n' + JSON.stringify(errors, null, 4);

@@ -55,2 +55,9 @@ {

"type": "string"
},
{
"description": "Ignore this request",
"name": "x-ignore",
"paramType": "header",
"required": false,
"type": "boolean"
}

@@ -152,2 +159,10 @@ ],

"type": "string"
},
{
"description": "Don't update listed fields",
"name": "x-ignore",
"paramType": "header",
"required": false,
"type": "string",
"allowMultiple": true
}

@@ -327,10 +342,11 @@ ],

"nickname": "findPetsByTags",
"notes": "Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.",
"notes": "Muliple tags can be provided with multple query parameters.",
"parameters": [
{
"description": "Tags to filter by",
"name": "tags",
"name": "tag",
"paramType": "query",
"required": true,
"type": "string"
"type": "string",
"allowMultiple": true
}

@@ -337,0 +353,0 @@ ],

2

package.json
{
"name": "swagger-schema",
"version": "0.5.0",
"version": "0.6.0",
"description": "Swagger schema helpers",

@@ -5,0 +5,0 @@ "dependencies": {

@@ -149,2 +149,11 @@ /**

}
// convert to items if allowMultiple
if (parameter.allowMultiple &&
constants.allowMultiple.indexOf(parameter.paramType) >= 0) {
schema.properties[parameter.name] = {
type: 'array',
items: property,
};
}
});

@@ -151,0 +160,0 @@

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