Merge branch 'mattpolzin-nullable-can-be-false'

master
Evgeny Poberezkin 2019-02-09 11:46:39 +00:00
commit 0cf6e9822d
3 changed files with 11 additions and 5 deletions

View File

@ -70,7 +70,7 @@ function Ajv(opts) {
if (opts.formats) addInitialFormats(this);
addDefaultMetaSchema(this);
if (typeof opts.meta == 'object') this.addMetaSchema(opts.meta);
if (opts.nullable) this.addKeyword('nullable', {metaSchema: {const: true}});
if (opts.nullable) this.addKeyword('nullable', {metaSchema: {type: 'boolean'}});
addInitialSchemas(this);
}

View File

@ -79,7 +79,7 @@
"glob": "^7.0.0",
"if-node-version": "^1.0.0",
"js-beautify": "^1.7.3",
"jshint": "^2.9.4",
"jshint": "2.9.7",
"json-schema-test": "^2.0.0",
"karma": "^3.0.0",
"karma-chrome-launcher": "^2.2.0",

View File

@ -1520,9 +1520,15 @@ describe('Ajv Options', function () {
testNotNullable({type: ['number']});
});
it('"nullable" keyword must be "true" if present', function() {
should.throw(function() {
ajv.compile({nullable: false});
it('should respect "nullable" == false with opts.nullable == true', function() {
testNotNullable({
type: 'number',
nullable: false
});
testNotNullable({
type: ['number'],
nullable: false
});
});
});