@kravc/schema 2.5.0 → 2.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Validator.js +2 -2
- package/src/Validator.spec.js +3 -3
package/package.json
CHANGED
package/src/Validator.js
CHANGED
|
@@ -43,7 +43,7 @@ class Validator {
|
|
|
43
43
|
this._jsonSchemasMap = keyBy(jsonSchemas, 'id')
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
validate(object, schemaId,
|
|
46
|
+
validate(object, schemaId, shouldNullifyEmptyValues = false) {
|
|
47
47
|
const jsonSchema = this._jsonSchemasMap[schemaId]
|
|
48
48
|
|
|
49
49
|
if (!jsonSchema) {
|
|
@@ -82,7 +82,7 @@ class Validator {
|
|
|
82
82
|
|
|
83
83
|
let validationErrors = this._engine.getLastErrors()
|
|
84
84
|
|
|
85
|
-
if (!
|
|
85
|
+
if (!shouldNullifyEmptyValues) {
|
|
86
86
|
throw new ValidationError(schemaId, result, validationErrors)
|
|
87
87
|
}
|
|
88
88
|
|
package/src/Validator.spec.js
CHANGED
|
@@ -40,7 +40,7 @@ describe('Validator', () => {
|
|
|
40
40
|
})
|
|
41
41
|
})
|
|
42
42
|
|
|
43
|
-
describe('.validate(object, schemaId,
|
|
43
|
+
describe('.validate(object, schemaId, shouldNullifyEmptyValues = false)', () => {
|
|
44
44
|
it('returns validated, cleaned and normalized object', () => {
|
|
45
45
|
const validator = new Validator(SCHEMAS)
|
|
46
46
|
|
|
@@ -227,7 +227,7 @@ describe('Validator', () => {
|
|
|
227
227
|
})
|
|
228
228
|
})
|
|
229
229
|
|
|
230
|
-
describe('.validate(object, schemaId,
|
|
230
|
+
describe('.validate(object, schemaId, shouldNullifyEmptyValues = false)', () => {
|
|
231
231
|
it('throws validation error for attributes not matching format or pattern', () => {
|
|
232
232
|
const validator = new Validator(SCHEMAS)
|
|
233
233
|
|
|
@@ -247,7 +247,7 @@ describe('Validator', () => {
|
|
|
247
247
|
})
|
|
248
248
|
})
|
|
249
249
|
|
|
250
|
-
describe('.validate(object, schemaId,
|
|
250
|
+
describe('.validate(object, schemaId, shouldNullifyEmptyValues = true)', () => {
|
|
251
251
|
it('returns input with cleaned up null values for not required attributes', () => {
|
|
252
252
|
const validator = new Validator(SCHEMAS)
|
|
253
253
|
|