json-schema-library
Advanced tools
Comparing version 2.3.2 to 2.4.0
@@ -10,3 +10,3 @@ const getTypeOf = require("./getTypeOf"); | ||
* @param {Mixed} data - the data to iterate | ||
* @param {Function} callback - will be called with (data, schema) on each item | ||
* @param {Function} callback - will be called with (schema, data, pointer) on each item | ||
* @param {String} pointer - pointer to given data | ||
@@ -13,0 +13,0 @@ */ |
@@ -33,3 +33,3 @@ const getTypeOf = require("./getTypeOf"); | ||
if (receivedType !== expectedType) { | ||
if (receivedType !== expectedType && (!Array.isArray(expectedType) || !expectedType.includes(receivedType))) { | ||
return [core.errors.typeError({ received: receivedType, expected: expectedType, value, pointer })]; | ||
@@ -36,0 +36,0 @@ } |
{ | ||
"name": "json-schema-library", | ||
"version": "2.3.2", | ||
"version": "2.4.0", | ||
"description": "Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "npm run test-unit; npm run test-integration", | ||
"test-integration": "mocha --recursive 'test/integration/**/*.test.js' -R spec; exit 0", | ||
"test-unit": "mocha --recursive 'test/unit/**/*.test.js' -R spec; exit 0", | ||
"tdd": "watch 'npm run test-unit' lib/ test/; exit 0", | ||
"test": "npm run test-unit && npm run test-integration", | ||
"test-integration": "mocha --recursive -R spec test/integration/**/*.test.js", | ||
"test-unit": "mocha --recursive -R spec test/unit/**/*.test.js", | ||
"tdd": "watch \"npm run test-unit\" lib/ test/", | ||
"coverage": "nyc npm run test --reporter=lcov" | ||
@@ -37,2 +37,2 @@ }, | ||
} | ||
} | ||
} |
@@ -20,2 +20,3 @@ # Tasks | ||
- [ ] -- Features -- anyOf | ||
- [✓] -- Features -- type-array | ||
- [✓] -- Features -- patternProperties | ||
@@ -22,0 +23,0 @@ - [✓] -- Features -- uniqueItems |
const expect = require("chai").expect; | ||
const addValidator = require("../../lib/addValidator"); | ||
const Core = require("../../lib/cores/draft04"); | ||
const Core = require("../../lib/cores/Draft04"); | ||
@@ -5,0 +5,0 @@ describe("addValidator", () => { |
const expect = require("chai").expect; | ||
const each = require("../../lib/each"); | ||
const Core = require("../../lib/cores/draft04"); | ||
const Core = require("../../lib/cores/Draft04"); | ||
@@ -5,0 +5,0 @@ describe("each", () => { |
const expect = require("chai").expect; | ||
const getSchema = require("../../lib/getSchema"); | ||
const Core = require("../../lib/cores/draft04"); | ||
const Core = require("../../lib/cores/Draft04"); | ||
@@ -5,0 +5,0 @@ describe("getSchema", () => { |
/* eslint quote-props: 0, no-unused-expressions: 0 */ | ||
const expect = require("chai").expect; | ||
const isValid = require("../../lib/isValid"); | ||
const Core = require("../../lib/cores/draft04"); | ||
const Core = require("../../lib/cores/Draft04"); | ||
@@ -6,0 +6,0 @@ |
const expect = require("chai").expect; | ||
const step = require("../../lib/step"); | ||
const Core = require("../../lib/cores/draft04"); | ||
const Core = require("../../lib/cores/Draft04"); | ||
@@ -6,0 +6,0 @@ |
const expect = require("chai").expect; | ||
const validate = require("../../lib/validate"); | ||
const Core = require("../../lib/cores/draft04"); | ||
const Core = require("../../lib/cores/Draft04"); | ||
@@ -584,2 +584,18 @@ | ||
}); | ||
describe("arrays of types", () => { | ||
it("should not return an error for a valid type", () => { | ||
let errors = validate(core, { type: ["object", "null"] }, {}); | ||
expect(errors).to.have.length(0); | ||
errors = validate(core, { type: ["object", "null"] }, null); | ||
expect(errors).to.have.length(0); | ||
}); | ||
it("should return a TypeErrpr if passed type is not within array", () => { | ||
let errors = validate(core, { type: ["object", "null"] }, []); | ||
expect(errors).to.have.length(1); | ||
expect(errors[0].name).to.eq("TypeError"); | ||
}); | ||
}); | ||
}); |
const expect = require("chai").expect; | ||
const validateAsync = require("../../lib/validateAsync"); | ||
const Core = require("../../lib/cores/draft04"); | ||
const Core = require("../../lib/cores/Draft04"); | ||
const addValidator = require("../../lib/addValidator"); | ||
@@ -5,0 +5,0 @@ |
272511
5502