From 53b5682cb7a28f686b05842fa1ea3dea71fea870 Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin Date: Sat, 13 Jul 2019 21:38:44 +0100 Subject: [PATCH] fix: the unknown keyword in the schema without known keywords inside compound schema (e.g. anyOf) is ignored with strictKeywords option --- lib/dot/definitions.def | 4 +++- spec/options/strictKeywords.spec.js | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/dot/definitions.def b/lib/dot/definitions.def index cdbe140..b68e064 100644 --- a/lib/dot/definitions.def +++ b/lib/dot/definitions.def @@ -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)) #}} diff --git a/spec/options/strictKeywords.spec.js b/spec/options/strictKeywords.spec.js index b212d15..4895b78 100644 --- a/spec/options/strictKeywords.spec.js +++ b/spec/options/strictKeywords.spec.js @@ -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 {