fix: the unknown keyword in the schema without known keywords inside compound schema (e.g. anyOf) is ignored with strictKeywords option

master
Evgeny Poberezkin 2019-07-13 21:38:44 +01:00
parent 669bf96c79
commit 53b5682cb7
2 changed files with 16 additions and 1 deletions

View File

@ -63,7 +63,9 @@
{{## def.nonEmptySchema:_schema:
it.util.schemaHasRules(_schema, it.RULES.all)
(it.opts.strictKeywords
? typeof _schema == 'object' && Object.keys(_schema).length > 0
: it.util.schemaHasRules(_schema, it.RULES.all))
#}}

View File

@ -49,6 +49,19 @@ describe('strictKeywords option', function() {
});
});
describe('unknown keyword inside schema that has no known keyword in compound keyword', function() {
it('should throw an error given an unknown keyword when strictKeywords is true', function() {
var ajv = new Ajv({strictKeywords: true});
var schema = {
anyOf: [
{
unknownKeyword: 1
}
]
};
should.throw(function() { ajv.compile(schema); });
});
});
function getLogger(output) {
return {