Skip to content
This repository has been archived by the owner on Aug 25, 2018. It is now read-only.

Better error message for missing type when using required #50

Closed
OzzieOrca opened this issue Aug 3, 2015 · 1 comment
Closed

Better error message for missing type when using required #50

OzzieOrca opened this issue Aug 3, 2015 · 1 comment

Comments

@OzzieOrca
Copy link

It seems inconsistent that in a schema, type is required but only when using required.

These are the same blocks of code but with different lines commented out.

This works fine:

schema:
  type: object
  properties:
    menu:
      type: object
#  required: [menu]

This also works fine:

schema:
  type: object
  properties:
    menu:
      type: object
  required: [menu]

This gives a horrible error. I believe I copied the base config an example (mentioned at the bottom) and then added required to it:

schema:
#  type: object
  properties:
    menu:
      type: object
  required: [menu]

It gave the following error message:

compile object
error line 1:8
{ properties: 
   { menu: 
      { type: 'object',
        constraint: '((true) && (!next.exists() || next.hasChildren())) && (next == null || (true))' } },
  required: [ 'menu' ],
  constraint: 'true' }
cannot validate schema node with type schema
data was on path: /required
the schema constraint was defined at 
Unknown property (not in schema)
run with -v option for fuller error messages

This is not a very descriptive error message. I mean you can kinda pick it out from the message saying that the type is schema (which isn't one of the valid types in the docs) and some problem with the /required path but it doesn't mean much to a first time user. It would be great if it could be something along the lines of on root schema, type attribute must be set when using required attribute

Also an issue in the docs that mislead me:
In the Constraints section, the example code doesn't have a type under $userid. I copied that code and then added required to it which created this error. I'm not sure if type should be required or not in all cases but definitely needs to be documented that the required attribute needs it.

@tomlarkworthy
Copy link
Contributor

"required" allowed for any type now (including untyped), fixed in 0.0.33, thanks for reporting!

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

No branches or pull requests

2 participants