# HG changeset patch # User Kim Alvefur # Date 1679836754 -7200 # Node ID 8592770be63af225842c4f77a6167ee0f8097517 # Parent 2cf8d98d8a283c7ded00ea5047a17c029664750b util.jsonschema: Implement 'dependentRequired' If this field exists, then these fields must also exist. diff -r 2cf8d98d8a28 -r 8592770be63a spec/util_jsonschema_spec.lua --- a/spec/util_jsonschema_spec.lua Sun Mar 26 13:13:31 2023 +0200 +++ b/spec/util_jsonschema_spec.lua Sun Mar 26 15:19:14 2023 +0200 @@ -19,7 +19,6 @@ ["const.json:9"] = "deepcompare", ["contains.json:0:5"] = "distinguishing objects from arrays", ["defs.json"] = "need built-in meta-schema", - ["dependentRequired.json"] = "NYI", ["dependentSchemas.json"] = "NYI", ["dynamicRef.json"] = "NYI", ["enum.json:1:3"] = "deepcompare", diff -r 2cf8d98d8a28 -r 8592770be63a teal-src/prosody/util/jsonschema.tl --- a/teal-src/prosody/util/jsonschema.tl Sun Mar 26 13:13:31 2023 +0200 +++ b/teal-src/prosody/util/jsonschema.tl Sun Mar 26 15:19:14 2023 +0200 @@ -295,6 +295,18 @@ 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 diff -r 2cf8d98d8a28 -r 8592770be63a util/jsonschema.lua --- a/util/jsonschema.lua Sun Mar 26 13:13:31 2023 +0200 +++ b/util/jsonschema.lua Sun Mar 26 15:19:14 2023 +0200 @@ -206,6 +206,18 @@ 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