From 4bc62438dbabb8fbe7ff3c4eca69c30cc04dd8bd Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 26 Mar 2023 15:19:14 +0200 Subject: util.jsonschema: Implement 'dependentRequired' If this field exists, then these fields must also exist. --- util/jsonschema.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'util/jsonschema.lua') diff --git a/util/jsonschema.lua b/util/jsonschema.lua index be0b72fd..1c4dcfbd 100644 --- a/util/jsonschema.lua +++ b/util/jsonschema.lua @@ -206,6 +206,18 @@ function complex_validate(schema, data, root) end end + if schema.dependentRequired then + for k, reqs in pairs(schema.dependentRequired) do + if data[k] ~= nil then + for _, req in ipairs(reqs) do + if data[req] == nil then + return false + end + end + end + end + end + if schema.propertyNames ~= nil then for k in pairs(data) do if not validate(schema.propertyNames, k, root) then -- cgit v1.2.3