enjoi
enjoi copied to clipboard
schema missing a 'type' or '$ref' or 'enum'
Hi,
JSON schema simplified below throws warning and does not create Joi object.
I'm not sure if this is a bug, or whether object
type is default, but I validated schema using several validators and they worked as expected. ('type', '$ref', 'enum' seems not to be mandatory)
Sample Code
const Joi = require("joi");
const Enjoi = require("enjoi");
const jsonSchema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"page": { "type": "integer" },
"limit": { "type": "integer" }
}
}
Joi.assert({ limit: "abc" }, Enjoi.schema(jsonSchema));
Actual Result
schema missing a 'type' or '$ref' or 'enum'
Expected Result
Joi assertion error
Thanks,
I think it’s open to interpretation. Schema definition says it must be a string or array and if a string it must be one of the known primitives.
Also:
An instance validates if and only if the instance is in any of the sets listed for this keyword.
I'm also confused about this, but I interpreted it as not mandatory, because it is not explicitly written anywhere that it is required.
An instance validates if and only if the instance is in any of the sets listed for this keyword.
I think this sentence is also ambiguous. Yes, instance validates if and only if the instance is in any of the sets listed for this keyword, but what if there isn't any sets for this keyword.
In my opinion type
should be mandatory. However, JSON validators I tried has this assumption: type
is optional and in the lack of type
it is object
. Additionally, some JSON schema converters I use (i.e. openapi-jsonschema-parameters) also does not generate type
property.
Would you please consider to add this assumption to enjoi
? It wouldn't break backward compatibility and ease workflow regarding other OpenAPI tools.
Will consider...