# HG changeset patch # User Kim Alvefur # Date 1615254230 -3600 # Node ID 58c534bac798ce49225c905d350d50b82fe0d833 # Parent c73744fa3bdfb270a9bee859280a9b614578a2af util.jsonschema: Implement "propertyNames" This is a bit special in Lua as tables are not limited to string keys diff -r c73744fa3bdf -r 58c534bac798 teal-src/util/jsonschema.tl --- a/teal-src/util/jsonschema.tl Tue Mar 09 02:41:47 2021 +0100 +++ b/teal-src/util/jsonschema.tl Tue Mar 09 02:43:50 2021 +0100 @@ -54,6 +54,7 @@ dependentRequired : { string : { string } } additionalProperties: schema_t patternProperties: schema_t + propertyNames : schema_t -- xml record xml_t @@ -239,6 +240,9 @@ if schema.properties then local additional : schema_t | boolean = schema.additionalProperties or true for k, v in pairs(data) do + if schema.propertyNames and not validate(schema.propertyNames, k) then + return false + end local s = schema.properties[k as string] or additional as schema_t if not validate(s, v) then return false @@ -246,6 +250,9 @@ end elseif schema.additionalProperties then for k, v in pairs(data) do + if schema.propertyNames and not validate(schema.propertyNames, k) then + return false + end if not validate(schema.additionalProperties, v) then return false end diff -r c73744fa3bdf -r 58c534bac798 util/jsonschema.lua --- a/util/jsonschema.lua Tue Mar 09 02:41:47 2021 +0100 +++ b/util/jsonschema.lua Tue Mar 09 02:43:50 2021 +0100 @@ -158,6 +158,9 @@ if schema.properties then local additional = schema.additionalProperties or true for k, v in pairs(data) do + if schema.propertyNames and not validate(schema.propertyNames, k) then + return false + end local s = schema.properties[k] or additional if not validate(s, v) then return false @@ -165,6 +168,9 @@ end elseif schema.additionalProperties then for k, v in pairs(data) do + if schema.propertyNames and not validate(schema.propertyNames, k) then + return false + end if not validate(schema.additionalProperties, v) then return false end