Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

schema missing a 'type' or '$ref' or 'enum' #57

Open
ozum opened this issue Aug 29, 2018 · 3 comments
Open

schema missing a 'type' or '$ref' or 'enum' #57

ozum opened this issue Aug 29, 2018 · 3 comments

Comments

@ozum
Copy link

ozum commented Aug 29, 2018

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,

@tlivings
Copy link
Owner

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.

@ozum
Copy link
Author

ozum commented Aug 30, 2018

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.

@tlivings tlivings added wontfix and removed wontfix labels Aug 30, 2018
@tlivings
Copy link
Owner

Will consider...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants