Closed d-adamkiewicz closed 12 years ago
Hi, I'm not sure if it's bug or I'm doing something wrong
var JSV = require('JSV').JSV; var env = JSV.createEnvironment(); var json, schema; var result = env.validate(json = {Z:1}, schema = {type: 'object', patternProperties: {'[a-z]': {type:'number'}}}); console.log('\njson:\n' + JSON.stringify(json, null, 4) + '\nschema:\n' + JSON.stringify(schema, null, 4)); if (result.errors.length === 0) { console.log('success'); } else { console.log('failure'); } result = env.validate(json = {a:1}, schema = {type: 'object', patternProperties: {'[A-Z]': {type:'number'}}}); console.log('\njson:\n' + JSON.stringify(json, null, 4) + '\nschema:\n' + JSON.stringify(schema, null, 4)); if (result.errors.length === 0) { console.log('success'); } else { console.log('failure'); } result = env.validate(json = {a:1}, schema = {type: 'object', patternProperties: {'^a\d': {type:'number'}}}); console.log('\njson:\n' + JSON.stringify(json, null, 4) + '\nschema:\n' + JSON.stringify(schema, null, 4)); if (result.errors.length === 0) { console.log('success'); } else { console.log('failure'); }
You need to use "additionalProperties" : false to cause errors to be thrown on undefined properties.
"additionalProperties" : false
Hi, I'm not sure if it's bug or I'm doing something wrong
- the following code reports always success. It seems regexp isn't taken into account.
var JSV = require('JSV').JSV; var env = JSV.createEnvironment(); var json, schema; var result = env.validate(json = {Z:1}, schema = {type: 'object', patternProperties: {'[a-z]': {type:'number'}}}); console.log('\njson:\n' + JSON.stringify(json, null, 4) + '\nschema:\n' + JSON.stringify(schema, null, 4)); if (result.errors.length === 0) { console.log('success'); } else { console.log('failure'); } result = env.validate(json = {a:1}, schema = {type: 'object', patternProperties: {'[A-Z]': {type:'number'}}}); console.log('\njson:\n' + JSON.stringify(json, null, 4) + '\nschema:\n' + JSON.stringify(schema, null, 4)); if (result.errors.length === 0) { console.log('success'); } else { console.log('failure'); } result = env.validate(json = {a:1}, schema = {type: 'object', patternProperties: {'^a\d': {type:'number'}}}); console.log('\njson:\n' + JSON.stringify(json, null, 4) + '\nschema:\n' + JSON.stringify(schema, null, 4)); if (result.errors.length === 0) { console.log('success'); } else { console.log('failure'); }