From f716227d0a644259287e9df40acefd9390163a73 Mon Sep 17 00:00:00 2001 From: Marco Porsch Date: Wed, 23 Aug 2023 15:41:15 +0200 Subject: [PATCH] check the type constraint first because others might rely on it --- include/valijson/schema_parser.hpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/include/valijson/schema_parser.hpp b/include/valijson/schema_parser.hpp index 0c0d5da..90d64b1 100644 --- a/include/valijson/schema_parser.hpp +++ b/include/valijson/schema_parser.hpp @@ -624,6 +624,14 @@ private: updatedScope = currentScope; } + // Add the type constraint first to be the first one to check because other constraints may rely on it + if ((itr = object.find("type")) != object.end()) { + rootSchema.addConstraintToSubschema( + makeTypeConstraint(rootSchema, rootNode, itr->second, updatedScope, nodePath + "/type", fetchDoc, + docCache, schemaCache), + &subschema); + } + if ((itr = object.find("allOf")) != object.end()) { rootSchema.addConstraintToSubschema( makeAllOfConstraint(rootSchema, rootNode, itr->second, @@ -925,13 +933,6 @@ private: } } - if ((itr = object.find("type")) != object.end()) { - rootSchema.addConstraintToSubschema( - makeTypeConstraint(rootSchema, rootNode, itr->second, updatedScope, nodePath + "/type", fetchDoc, - docCache, schemaCache), - &subschema); - } - if ((itr = object.find("uniqueItems")) != object.end()) { opt::optional constraint = makeUniqueItemsConstraint(itr->second); if (constraint) {