karenetheridge / JSON-Schema-Modern

Validate data against a schema using a JSON Schema
https://metacpan.org/release/JSON-Schema-Modern/
Other
10 stars 1 forks source link

support scalarref bools in instance data #46

Closed karenetheridge closed 3 years ago

karenetheridge commented 3 years ago

With a configuration setting, accept \0 and \1 as valid boolean types in instance data.

As these values are accepted by Cpanel::JSON::XS::encode_json, JSON::PP::encode_json and Mojo::JSON::encode_json (the only JSON encoders that anyone should care about IMO), treating these values as booleans will allow for validating a document just before it is json-encoded (for example being sent as the response to an http request with Content-Type: application/json).

karenetheridge commented 3 years ago

We could potentially support \0 and \1 in ad-hoc schemas as well, but to do so without a lot of extra code everywhere (we can no longer evaluate true and false in boolean context, as \0 evaluates to true - so we'd need a is_true($val) helper function) we would need to mutate the schema as we traverse it -- which would also require a fair bit of code scattered throughout (it's not just subschemas that can be booleans, but also keyword values as well -- in enum, const, uniqueItems, $vocabulary, $recursiveAnchor, deprecated, readOnly, writeOnly -- but we can mutate those in assert_keyword_type).

karenetheridge commented 3 years ago

done in release 0.515.