brandur / json_schema

A JSON Schema V4 and Hyperschema V4 parser and validator.
MIT License
230 stars 45 forks source link

require for all parameters? #48

Closed panSarin closed 8 years ago

panSarin commented 8 years ago

Hey i can't find it anywhere in JSON Schema documentations, so I decided to ask it here. So, can i define that all my parameters defined in json schema are required? Since i define json schema and then i want to validate my response with json_schema gem, i expect all fields that i defined to exists in my response. So is there any way to do something like

  "required": [all] 

or

  "required": [*]

so i don't need to copy all parameters names to the required array ?

brandur commented 8 years ago

Hey @panSarin,

This is indeed kind of a hole in the V4 spec in that there isn't really a good way of doing that.

The next iteration of the specification, V5, will like include a new property called strictProperties that does what you need.

The good news is that this gem supports strictProperties out of the box because we wanted it for our schemas. The bad news is that it's not technically part of the current specification so it probably won't be widely supported by other validators. Hopefully this will change soon, but the last time I checked, V5 was still in limbo.

Closing this out, but lemme know if you have anymore questions about it!

panSarin commented 8 years ago

Thank you for you help! Greetings!