swagger-schema
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -26,2 +26,3 @@ /** | ||
// defaults | ||
options = lodash.defaults(options || {}, { | ||
@@ -31,5 +32,6 @@ setup: true, | ||
this.schema = jjv(); | ||
this.coerceSchema = jjv(); | ||
this.schemas = [this.schema, this.coerceSchema]; | ||
this.env = jjv(); | ||
this.env.defaultOptions.checkRequired = true; | ||
this.env.defaultOptions.useDefault = true; | ||
this.env.defaultOptions.useCoerce = false; | ||
@@ -40,3 +42,3 @@ if (options.setup) this.setup(); | ||
Environment.prototype.setup = function() { | ||
this.coerceSchema.addTypeCoercion('array', function(v) { | ||
this.env.addTypeCoercion('array', function(v) { | ||
if (!Array.isArray(v)) { | ||
@@ -48,3 +50,3 @@ return typeof v === 'undefined' ? [] : [v]; | ||
this.coerceSchema.addTypeCoercion('integer', function(v) { | ||
this.env.addTypeCoercion('integer', function(v) { | ||
if (typeof v === 'string' && v.match(/^\-?\d+$/)) { | ||
@@ -56,3 +58,3 @@ return parseInt(v, 10); | ||
this.coerceSchema.addTypeCoercion('number', function(v) { | ||
this.env.addTypeCoercion('number', function(v) { | ||
if (typeof v === 'string' && v.match(/^(\d+|\d*\.\d+|\d+\.\d*)$/)) { | ||
@@ -64,3 +66,3 @@ return parseFloat(v); | ||
this.coerceSchema.addTypeCoercion('boolean', function(v) { | ||
this.env.addTypeCoercion('boolean', function(v) { | ||
if (typeof v === 'string') { | ||
@@ -79,6 +81,9 @@ return ['', '0', 'false', 'no'].indexOf(v) < 0; | ||
options = options || {}; | ||
if (options.coerce) { | ||
return this.coerceSchema.validate(schema, data, options); | ||
if (options.hasOwnProperty('coerce')) { | ||
options.useCoerce = options.coerce; | ||
delete options.coerce; | ||
} | ||
return this.schema.validate(schema, data, options); | ||
return this.env.validate(schema, data, options); | ||
}; | ||
@@ -105,5 +110,3 @@ | ||
Environment.prototype.addSchema = function(name, data) { | ||
this.schemas.forEach(function(env) { | ||
env.addSchema(name, data); | ||
}); | ||
this.env.addSchema(name, data); | ||
}; | ||
@@ -110,0 +113,0 @@ |
{ | ||
"name": "swagger-schema", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Swagger schema helpers", | ||
"dependencies": { | ||
"jjv": "0.3.4", | ||
"lodash": "*" | ||
"jjv": "1.0.0", | ||
"lodash": "^2.4.1" | ||
}, | ||
@@ -9,0 +9,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
59205
2019
1
+ Addedjjv@1.0.0(transitive)
+ Addedlodash@2.4.2(transitive)
- Removedjjv@0.3.4(transitive)
- Removedlodash@4.17.21(transitive)
Updatedjjv@1.0.0
Updatedlodash@^2.4.1