openapi-enforcer
Advanced tools
Comparing version 1.22.0 to 1.22.1
@@ -7,2 +7,12 @@ # Change Log | ||
## 1.22.1 | ||
### Fixed | ||
- **Exception Skip Codes Bug Fix** | ||
The exception skip codes that were defined via the options were not being carried through to child components. This | ||
fix allows those settings to be carried. Exception skip codes defined by an instance (see change 1.22.0) are still | ||
limited to just the component. | ||
## 1.22.0 | ||
@@ -9,0 +19,0 @@ |
{ | ||
"name": "openapi-enforcer", | ||
"version": "1.22.0", | ||
"version": "1.22.1", | ||
"description": "Library for validating, parsing, and formatting data against open api schemas.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -71,3 +71,3 @@ /** | ||
*/ | ||
function normalize (data, superOptions) { | ||
function normalize (data, refParser, superOptions) { | ||
const { definitionType, exception, production, result } = data; | ||
@@ -106,3 +106,3 @@ const skipCodes = superOptions.exceptionSkipCodes; | ||
const child = childData(data, i, validator.items); | ||
result.push(runChildValidator(child, superOptions)); | ||
result.push(runChildValidator(child, refParser, superOptions)); | ||
}); | ||
@@ -145,3 +145,3 @@ Object.freeze(result); | ||
enumerable: true, | ||
value: runChildValidator(child, superOptions) | ||
value: runChildValidator(child, refParser, superOptions) | ||
}); | ||
@@ -205,3 +205,3 @@ valueSet = true; | ||
enumerable: true, | ||
value: runChildValidator(data, superOptions) | ||
value: runChildValidator(data, refParser, superOptions) | ||
}); | ||
@@ -249,3 +249,3 @@ } | ||
const child = childData(data, i, validator.items); | ||
result.push(runChildValidator(child, superOptions)); | ||
result.push(runChildValidator(child, refParser, superOptions)); | ||
}); | ||
@@ -267,3 +267,3 @@ Object.freeze(result); | ||
enumerable: true, | ||
value: runChildValidator(child, superOptions) | ||
value: runChildValidator(child, refParser, superOptions) | ||
}); | ||
@@ -385,3 +385,3 @@ }); | ||
function runChildValidator(data, superOptions) { | ||
function runChildValidator(data, refParser, superOptions) { | ||
const validator = fn(data.validator, data); | ||
@@ -393,8 +393,8 @@ data.validator = validator; | ||
data.validator = data.validator.config; | ||
return normalize(data, superOptions); | ||
return normalize(data, refParser, superOptions); | ||
} else if (!subValidator || validateType(data.definitionType, Object.assign({}, data, { validator: subValidator }))) { | ||
return new data.context[validator.value](new ValidatorState(data)); | ||
return new data.context[validator.value](new ValidatorState(data), refParser, superOptions); | ||
} | ||
} else if (data.validator) { | ||
return normalize(data, superOptions); | ||
return normalize(data, refParser, superOptions); | ||
} else { | ||
@@ -401,0 +401,0 @@ return data.result; |
@@ -93,12 +93,16 @@ /** | ||
options.exceptionSkipCodes = options.hasOwnProperty('exceptionSkipCodes') | ||
? options.exceptionSkipCodes.reduce((p, c) => { | ||
p[c] = true; | ||
return p; | ||
}, {}) | ||
? Array.isArray(options.exceptionSkipCodes) | ||
? options.exceptionSkipCodes.reduce((p, c) => { | ||
p[c] = true; | ||
return p; | ||
}, {}) | ||
: options.exceptionSkipCodes | ||
: {}; | ||
options.exceptionEscalateCodes = options.hasOwnProperty('exceptionEscalateCodes') | ||
? options.exceptionEscalateCodes.reduce((p, c) => { | ||
p[c] = true; | ||
return p; | ||
}, {}) | ||
? Array.isArray(options.exceptionEscalateCodes) | ||
? options.exceptionEscalateCodes.reduce((p, c) => { | ||
p[c] = true; | ||
return p; | ||
}, {}) | ||
: options.exceptionEscalateCodes | ||
: {}; | ||
@@ -146,3 +150,3 @@ | ||
data.result = result = existing.value; | ||
definitionValidator(data, options) | ||
definitionValidator(data, refParser, options) | ||
} else { | ||
@@ -155,3 +159,3 @@ // store the full set of enforcer data | ||
if (!needsValidation) data.validator = true; | ||
definitionValidator(data, options); | ||
definitionValidator(data, refParser, options); | ||
} else { | ||
@@ -158,0 +162,0 @@ data.exception.message('Value must be a plain object'); |
@@ -277,2 +277,12 @@ const expect = require('chai').expect; | ||
describe('issue-140 - skip codes not respected by subcomponents', () => { | ||
it('will keep skip codes for subcomponents', async () => { | ||
const fullPath = path.resolve(resourcesPath, 'issue-140/openapi.yml'); | ||
const [value, err, warn] = await Enforcer(fullPath, { fullResult: true, componentOptions: { | ||
exceptionSkipCodes: ['WSCH006', 'EDEV001'] | ||
}}); | ||
expect(err).to.equal(undefined); | ||
}) | ||
}) | ||
describe('issue-145 - default with multiple types', () => { | ||
@@ -288,3 +298,3 @@ it('can have a default at the top and anyof subtypes', async () => { | ||
describe('issue-146 - ignore exception for specific instance', () => { | ||
describe('issue-140 - ignore exception for specific instance', () => { | ||
function getDefinition () { | ||
@@ -339,4 +349,11 @@ return { | ||
}); | ||
it('will not carry the exception to subcomponents', async () => { | ||
const def = getDefinition(); | ||
def['x-enforcer-exception-skip-codes'] = 'EDEV001'; | ||
const [value, err, warn] = await Enforcer(def, { fullResult: true }); | ||
expect(err.count).to.equal(2); | ||
}) | ||
}); | ||
}); |
1055583
115
20719