From 0318c70709428d33cd2113d53f8af1fc6e44c8a4 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 23 Mar 2015 18:42:17 +1100 Subject: [PATCH] json/schema: additionalProperties, patternProperties --- json/schema.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/json/schema.cpp b/json/schema.cpp index b4499ab2..9348752a 100644 --- a/json/schema.cpp +++ b/json/schema.cpp @@ -63,15 +63,27 @@ validate (json::tree::object &node, continue; } catch (const json::key_error&) { ; } + + if (additional != schema.cend ()) { + if (additional->second->is_boolean () && !additional->second->as_bool ()) + throw json::schema_error ("additionalProperties"); + + validate (*p->second, additional->second->as_object ()); + } } } } - if (pattern != schema.cend ()) - not_implemented (); + if (pattern != schema.cend ()) { + for (auto &cond: pattern->second->as_object ()) { + std::regex expr (cond.first, std::regex_constants::ECMAScript); - if (additional != schema.cend ()) - not_implemented (); + for (auto &props: node) { + if (std::regex_search (props.first, expr)) + validate (*props.second, cond.second->as_object ()); + } + } + } if (schema.has ("dependencies")) not_implemented ();