libucl
libucl copied to clipboard
Schema: validation error: schema is array instead of object
This should be a valid v4 schema:
{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "create domain", "description": "create a new domain in mailsys", "type": "object", "properties": { "domain": { "description": "fully qualified domain name", "type": "string", "format": "hostname" }, "type": {}, "relay_server": {}, "default": { "type": "object", "properties": { "sendcount_day": { "description": "number of recipients allowed daily", "type": "integer", "minValue": 0, "maxValue": 10000 }, "sendcount_month": { "description": "number of recipients allowed monthly", "type": "integer", "minValue": 0, "maxValue": 10000 }, "storage_space": { "description": "megabytes of storage space", "type": "integer", "minValue": 1000, "maxValue": 100000 } }, "additionalProperties": false } }, "oneOf": [ { "$ref":"#/definitions/type_local" }, { "$ref":"#/definitions/type_relay" } ], "required": ["domain","type"], "additionalProperties": false, "definitions": { "type_local": { "properties": { "type": { "enum": ["local"] } }, "required": ["type"] }, "type_relay": { "properties": { "type": { "enum": ["relay"] }, "relay_server": { "description": "server mail will be delivered to", "type": "string", "format": "hostname" } }, "required": ["type","relay_server"] } } }
But get the error in subject when I try to validate against it, for example with this object:
{ "domain":"foobar.org", "type": "relay", "relay_server":"foobar.net" }
So it cannot load schema or it cannot validate an object using this schema?
It load the schema, but does not validate with the error message:
validation error: schema is array instead of object
perhaps this is the way I load the schema?
local s = ucl.parser() s:parse_string(json_schema_loaded_from_file) local schema = s:get_object()
local res,err = parser:validate(schema)
And what if you load it from the file with something like
local res,err = parser:validate(schema_file)
That would help me to narrow the problem.
Yeah.. seems to work!
But its probably more efficient for me to load schema file once, its used alot.
Just an additional question: do you support $refs to local files, and is it possible to preload these?
I think the problem here is that lua <-> ucl interaction lacks of passing ucl objects as userdata. Instead, it copies the full structure of ucl object to a lua variable (e.g. a table or a primitive type) which involves copying. I think I aslo need to add zerocopy mechanisms to access ucl objects (at least for validation purposes). Maybe, I'll just pass everything as opaque userdata with method unwrap
which would copy ucl object structure into a lua native variable.