pkgjs / support

Package Support Format
MIT License
24 stars 7 forks source link

Validate is very noisy and does not offer simple advice for invalid response type #45

Closed shadowspawn closed 2 years ago

shadowspawn commented 3 years ago

I entered an invalid type during testing and was surprised by the output. This was my first fail, so not sure if this is typical or I found a poorly handled case. Only the middle one "enum should be equal to one of the allowed values" seemed directly useful. The "type should be array" seems just wrong, as the "response" field is the one that may be an array?

(This is a file created by support create with just the "type" field modified.)

$ support validate                                                                                                                                  master
Error in support JSON
TYPE should be array

> 1 | {"versions":[{"version":"*","target":{"node":"lts"},"response":{"type":"invalid-type"},"backing":{"hobby":""}}]}
    |                                                                ^^^^^^^^^^^^^^^^^^^^^^^ πŸ‘ˆπŸ½  type should be array

ONEOF should match exactly one schema in oneOf

> 1 | {"versions":[{"version":"*","target":{"node":"lts"},"response":{"type":"invalid-type"},"backing":{"hobby":""}}]}
    |                                                                ^^^^^^^^^^^^^^^^^^^^^^^ πŸ‘ˆπŸ½  oneOf should match exactly one schema in oneOf

ENUM should be equal to one of the allowed values

> 1 | {"versions":[{"version":"*","target":{"node":"lts"},"response":{"type":"invalid-type"},"backing":{"hobby":""}}]}
    |                                                                        ^^^^^^^^^^^^^^ πŸ‘ˆπŸ½  enum should be equal to one of the allowed values

PATTERN should match pattern "regular-[1-7]"

> 1 | {"versions":[{"version":"*","target":{"node":"lts"},"response":{"type":"invalid-type"},"backing":{"hobby":""}}]}
    |                                                                        ^^^^^^^^^^^^^^ πŸ‘ˆπŸ½  pattern should match pattern "regular-[1-7]"

ONEOF should match exactly one schema in oneOf

> 1 | {"versions":[{"version":"*","target":{"node":"lts"},"response":{"type":"invalid-type"},"backing":{"hobby":""}}]}
    |                                                                        ^^^^^^^^^^^^^^ πŸ‘ˆπŸ½  oneOf should match exactly one schema in oneOf
shadowspawn commented 3 years ago

I tried a few more failures, and saw much simpler and more direct messages. Whew!

$ support validate
Error in support JSON
ADDTIONAL PROPERTY should NOT have additional properties

> 1 | {"versions":[{"version":"*","target":{"node":"*"},"response":{"type":"24-7"},"backxing":{"none":""}}]}
    |                                                                              ^^^^^^^^^^ 😲  backxing is not expected to be here!
mhdawson commented 3 years ago

The output is a result of the json validator used under the covers. It sometimes does have quite a few messages with only one being useful. Receptive to any suggestions/PRs that tweak to improve where possible.

mhdawson commented 3 years ago

I guess one option might be to pre-validate the response type. We'd have to see how easy/hard that is...

shadowspawn commented 2 years ago

Closing this as a first-experience comment, rather than a call for action. Thanks for the tool!