voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.54k stars 243 forks source link

add :require_all option in addition to :strict #295

Closed pkarman closed 8 years ago

pkarman commented 8 years ago

We want to test if example JSON adheres to the schema, esp for required and additionalProperties. However, the current :strict behavior is too strict.

The current behavior of :strict turns on an implied required for all properties. This PR makes that implicit requirement explicit, and off by default.

To get the current behavior, this PR would require:

JSON::Validator.validate(schema, {"a" => 1}, :strict => true, :require_all => true)

instead of simply :strict => true.

pkarman commented 8 years ago

fails too many tests this way. will re-open with reverse logic (keeping original behavior by default).

cec commented 8 years ago

@pkarman I second your opinion that we need a proper strict mode. I posted again on #103 where this was extensively discussed and also referenced your PR.

pkarman commented 8 years ago

@cec thanks. I hadn't realized there was such a history here. I implemented this PR in complete ignorance (though it is interesting I chose basically the same implementation as mentioned in #103).

This PR is closed though; I reimplemented in #296

Perhaps it will help if I add an example of the schema we are testing.

cec commented 8 years ago

@pkarman I'm sure that adding a schema will help others see the arguments behind this proposal, which I agree with completely.

I will join the discussion on #296 , which now I understand to be the one receiving some attention. I'll post an example schema of mine too.

Thank you!