swagger-enforcer
Advanced tools
Comparing version 1.3.9 to 1.3.10
@@ -84,21 +84,17 @@ /** | ||
if (schema.discriminator && value.hasOwnProperty(schema.discriminator)) { | ||
if (!schema.allOf && schema.discriminator && value.hasOwnProperty(schema.discriminator)) { | ||
const second = definitions[value[schema.discriminator]]; | ||
const schemaHasAllOf = Array.isArray(schema.allOf); | ||
schema = copy(schema); | ||
//schema = copy(schema); | ||
const allOf = (Array.isArray(second.allOf) ? second.allOf : [ second ]) | ||
.filter(s => s !== schema); | ||
(schemaHasAllOf ? schema.allOf : [ schema ]).forEach(s => { | ||
if (allOf.indexOf(s) !== -1) allOf.push(s); | ||
}); | ||
if (schemaHasAllOf) { | ||
schema.allOf = allOf; | ||
} else { | ||
schema = { | ||
type: 'object', | ||
allOf: allOf | ||
}; | ||
} | ||
const schemaCopy = Object.assign({}, schema); | ||
delete schemaCopy.discriminator; | ||
allOf.push(schemaCopy); | ||
schema = { | ||
type: 'object', | ||
allOf: allOf | ||
}; | ||
} | ||
@@ -112,6 +108,6 @@ | ||
schema.allOf.forEach(schema => { | ||
const data = applyTemplate(schema, definitions, params, options, {}); | ||
const data = applyTemplate(schema, definitions, params, options, valueNotProvided ? {} : value); | ||
if (data.applied) applications.push(data.value); | ||
}); | ||
applications.push(valueNotProvided ? {} : value); | ||
//applications.push(valueNotProvided ? {} : value); | ||
return { | ||
@@ -222,3 +218,3 @@ applied: applications.length > 2, | ||
const properties = schema.properties || {}; | ||
const requires = []; | ||
const requires = schema.required || []; | ||
let setDefault = false; | ||
@@ -229,3 +225,3 @@ | ||
const subSchema = schema.properties[property]; | ||
if (subSchema.required) requires.push(property); | ||
//if (subSchema.required) requires.push(property); | ||
if ((options.useTemplates && subSchema.hasOwnProperty('x-template')) || (options.useVariables && subSchema.hasOwnProperty('x-variable')) || (options.useDefaults && subSchema.hasOwnProperty('default')) || subSchema.type === 'object') { | ||
@@ -232,0 +228,0 @@ const data = result.hasOwnProperty(property) |
@@ -619,4 +619,4 @@ /** | ||
const day = +match[3]; | ||
const date = new Date(year, month, day); | ||
if (date.getFullYear() !== year || date.getMonth() !== month || date.getDate() !== day) { | ||
const date = new Date(value); | ||
if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month || date.getUTCDate() !== day) { | ||
context.error(at, 'Date does not exist on the calendar.', 'DATE'); | ||
@@ -623,0 +623,0 @@ } |
{ | ||
"name": "swagger-enforcer", | ||
"version": "1.3.9", | ||
"version": "1.3.10", | ||
"description": "Automatically validate a value against the swagger schema while you build it. Alternatively you can validate the final value.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -197,6 +197,6 @@ /** | ||
type: 'object', | ||
required: ['name'], | ||
properties: { | ||
name: { | ||
type: 'string', | ||
required: true | ||
type: 'string' | ||
}, | ||
@@ -416,4 +416,4 @@ age: { | ||
it('cat', () => { | ||
const o = applyDefaults(definitions.Cat, definitions, options, {}); | ||
expect(o).to.deep.equal({ hasFur: true, yarnBalls: 3 }); | ||
const o = applyDefaults(definitions.Cat, definitions, options, { petType: 'Cat'}); | ||
expect(o).to.deep.equal({ hasFur: true, petType: 'Cat', yarnBalls: 3 }); | ||
}); | ||
@@ -423,3 +423,3 @@ | ||
const o = applyDefaults(definitions.Pet, definitions, options, {}); | ||
expect(o).to.deep.equal({ hasFur: true }); | ||
expect(o).to.deep.equal({}); | ||
}); | ||
@@ -426,0 +426,0 @@ |
@@ -140,3 +140,3 @@ /** | ||
properties: { | ||
value2: { | ||
complete: { | ||
type: 'object', | ||
@@ -146,2 +146,9 @@ properties: { | ||
bar: { type: 'string', default: 'bar' } | ||
} | ||
}, | ||
partial: { | ||
type: 'object', | ||
properties: { | ||
foo: { type: 'string' }, | ||
bar: { type: 'string', default: 'bar' } | ||
}, | ||
@@ -155,4 +162,3 @@ required: ['foo'] | ||
const o = enforcer(schema, {}, options).enforce(); | ||
o.value.value2.foo = 'abc'; | ||
expect(o).to.deep.equal({ value: { value2: { foo: 'abc', bar: 'bar' } } }); | ||
expect(o).to.deep.equal({ value: { complete: { bar: 'bar' }}}); | ||
}); | ||
@@ -159,0 +165,0 @@ |
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
195303
3838