libucl icon indicating copy to clipboard operation
libucl copied to clipboard

Schema: validation error: schema is array instead of object

Open bjne opened this issue 9 years ago • 6 comments

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" }

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/26581489-schema-validation-error-schema-is-array-instead-of-object?utm_campaign=plugin&utm_content=tracker%2F483345&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F483345&utm_medium=issues&utm_source=github).

bjne avatar Sep 10 '15 09:09 bjne

So it cannot load schema or it cannot validate an object using this schema?

vstakhov avatar Sep 10 '15 11:09 vstakhov

It load the schema, but does not validate with the error message:

validation error: schema is array instead of object

bjne avatar Sep 10 '15 14:09 bjne

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)

bjne avatar Sep 10 '15 14:09 bjne

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.

vstakhov avatar Sep 10 '15 15:09 vstakhov

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?

bjne avatar Sep 10 '15 16:09 bjne

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.

vstakhov avatar Sep 11 '15 11:09 vstakhov