openapi-enforcer
Advanced tools
Comparing version 1.16.1 to 1.17.0
@@ -7,2 +7,10 @@ # Change Log | ||
## 1.17.0 | ||
### Added | ||
- **Examples Warn of Additional Properties** | ||
For a schema, the default behavior of an object is to allow additional properties. This can be problematic when examples have additional properties that the schema does not define. Now there is a global config option `Enforcer.config.examplesWarnAdditionalProperty` that defaults to `true` and will warn of examples with additional properties. To disable this behavior set the global config property to `false`. | ||
## 1.16.1 | ||
@@ -9,0 +17,0 @@ |
@@ -90,2 +90,3 @@ /** | ||
Enforcer.config = { | ||
examplesWarnAdditionalProperty: true, | ||
useNewRefParser: false | ||
@@ -92,0 +93,0 @@ }; |
{ | ||
"name": "openapi-enforcer", | ||
"version": "1.16.1", | ||
"version": "1.17.0", | ||
"description": "Library for validating, parsing, and formatting data against open api schemas.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -291,3 +291,7 @@ /** | ||
const value = this.enum.map((value, index) => { | ||
return deserializeAndValidate(this, child.at(index), value, { enum: false }); | ||
return deserializeAndValidate(this, child.at(index), value, { | ||
enum: false, | ||
escalateCodes, | ||
skipCodes | ||
}); | ||
}); | ||
@@ -303,3 +307,5 @@ Object.freeze(value); | ||
// TODO: should this produce an error or a warning? It's currently set to warn. | ||
const value = deserializeAndValidate(this, warn.at('example'), this.example, {}); | ||
const value = deserializeAndValidate(this, warn.at('example'), this.example, { | ||
isExample: true | ||
}); | ||
setProperty(this, 'example', freeze(value)); | ||
@@ -864,2 +870,14 @@ } | ||
/** | ||
* | ||
* @param schema | ||
* @param exception | ||
* @param value | ||
* @param {object} options | ||
* @param {boolean} [options.enum] Set to false to skip enum validation. | ||
* @param {boolean} [options.isExample] If the passed in value is an example then set this to true. | ||
* @param {boolean} [options.maxMin] Set to false to skip max min validation. | ||
* @param {'read', 'write} [options.readWriteMode] Set to 'read' if in read only mode or to 'write' if write only mode. | ||
* @returns {*} | ||
*/ | ||
function deserializeAndValidate(schema, exception, value, options) { | ||
@@ -866,0 +884,0 @@ let error; |
@@ -25,2 +25,16 @@ /** | ||
/** | ||
* | ||
* @param exception | ||
* @param map | ||
* @param schema | ||
* @param originalValue | ||
* @param options | ||
* @param {object} options | ||
* @param {boolean} [options.enum] Set to false to skip enum validation. | ||
* @param {boolean} [options.isExample] If the passed in value is an example then set this to true. | ||
* @param {boolean} [options.maxMin] Set to false to skip max min validation. | ||
* @param {'read', 'write} [options.readWriteMode] Set to 'read' if in read only mode or to 'write' if write only mode. | ||
* @returns {*} | ||
*/ | ||
function runValidate(exception, map, schema, originalValue, options) { | ||
@@ -188,2 +202,7 @@ let { validate, value } = Value.getAttributes(originalValue); | ||
runValidate(exception.at(key), map, schema.additionalProperties, value[key], options); | ||
} else if (options.isExample) { | ||
const enforcerConfig = require('../../').config | ||
if (enforcerConfig.examplesWarnAdditionalProperty === true) { | ||
exception.at(key).message('Property is an additional property'); | ||
} | ||
} | ||
@@ -190,0 +209,0 @@ } |
Sorry, the diff of this file is too big to display
1594370
20998