test: whitelisted unknown formats should be valid (remove warnings), #310

master
Evgeny Poberezkin 2016-10-16 12:13:18 +01:00
parent 9bd850d115
commit 01ff755d4b
6 changed files with 12 additions and 17 deletions

View File

@ -881,7 +881,7 @@ describe('Ajv Options', function () {
} }
}); });
it.skip('should throw during validation if unknown format is used via $data', function() { it.skip('should fail validation if unknown format is used via $data', function() {
test(new Ajv({v5: true, unknownFormats: true})); test(new Ajv({v5: true, unknownFormats: true}));
function test(ajv) { function test(ajv) {
@ -897,9 +897,7 @@ describe('Ajv Options', function () {
validate({foo: '20161016', bar: 'date'}) .should.equal(false); validate({foo: '20161016', bar: 'date'}) .should.equal(false);
validate({foo: '20161016'}) .should.equal(true); validate({foo: '20161016'}) .should.equal(true);
should.throw(function() { validate({foo: '2016-10-16', bar: 'unknown'}) .should.equal(false);
validate({foo: '2016-10-16', bar: 'unknown'});
});
} }
}); });
}); });
@ -967,10 +965,7 @@ describe('Ajv Options', function () {
validate({foo: '20161016'}) .should.equal(true); validate({foo: '20161016'}) .should.equal(true);
validate({foo: '2016-10-16', bar: 'allowed'}) .should.equal(true); validate({foo: '2016-10-16', bar: 'allowed'}) .should.equal(true);
validate({foo: '2016-10-16', bar: 'unknown'}) .should.equal(false);
should.throw(function() {
validate({foo: '2016-10-16', bar: 'unknown'});
});
} }
}); });
}); });

View File

@ -6,7 +6,7 @@ var jsonSchemaTest = require('json-schema-test')
, suite = require('./brower_test_suite') , suite = require('./brower_test_suite')
, after = require('./after_test'); , after = require('./after_test');
var instances = getAjvInstances(options); var instances = getAjvInstances(options, {unknownFormats: ['allowedUnknown']});
var remoteRefs = { var remoteRefs = {
'http://localhost:1234/integer.json': require('./JSON-Schema-Test-Suite/remotes/integer.json'), 'http://localhost:1234/integer.json': require('./JSON-Schema-Test-Suite/remotes/integer.json'),

View File

@ -1,12 +1,12 @@
[ [
{ {
"description": "unknown format is always valid", "description": "whitelisted unknown format is valid",
"schema": { "schema": {
"format": "unknownformat" "format": "allowedUnknown"
}, },
"tests": [ "tests": [
{ {
"description": "anything is valid", "description": "any string is valid",
"data": "any value", "data": "any value",
"valid": true "valid": true
} }

View File

@ -72,7 +72,7 @@
"server": { "server": {
"type": "string", "type": "string",
"anyOf": [ "anyOf": [
{ "format": "host-name" }, { "format": "hostname" },
{ "format": "ipv4" }, { "format": "ipv4" },
{ "format": "ipv6" } { "format": "ipv6" }
] ]

View File

@ -6,7 +6,7 @@ var jsonSchemaTest = require('json-schema-test')
, suite = require('./brower_test_suite') , suite = require('./brower_test_suite')
, after = require('./after_test'); , after = require('./after_test');
var instances = getAjvInstances(options, { v5: true }); var instances = getAjvInstances(options, { v5: true, unknownFormats: ['allowedUnknown'] });
jsonSchemaTest(instances, { jsonSchemaTest(instances, {

View File

@ -204,14 +204,14 @@
] ]
}, },
{ {
"description": "formatMaximum is valid with unknown format", "description": "formatMaximum is valid with whitelisted unknown format",
"schema": { "schema": {
"format": "unknown", "format": "allowedUnknown",
"formatMaximum": "2015" "formatMaximum": "2015"
}, },
"tests": [ "tests": [
{ {
"description": "always valid", "description": "valid string",
"data": "2016", "data": "2016",
"valid": true "valid": true
} }