-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for symbolized keys #91
Comments
Have you got an example for what this trips up on? |
For example, Using But like this Refs:
|
This uses a refinement to support indifferent access for user-provided hashes. The interface is purposefully limited to prevent future use of hash methods that may not work as expected. Refinements are tricky, though, since you lose them whenever they're out of scope (eg, passing a hash to `include?` doesn't call the refinement's `==` method). I initially tried using activesupport's `HashWithIndifferentAccess` but it doesn't work for data hashes because `insert_property_defaults` needs to operate on the actual hash. Requiring all of activesupport just for `HashWithIndifferentAccess` also felt like a pain. The refinement works slightly different from `HashWithIndifferentAccess` because it leaves the keys as whatever type they already are. That might be a little confusing in error objects and `insert_property_defaults` but at least it's consistent with whatever is passed in. Symbol keys are mostly being tested by running the json-schema-test-suite tests again with symbol keys (using `symbolize_names: true` when parsing JSON). I also pulled those tests into their own file and cleaned things up. Addresses: - #91 - #123
This uses a refinement to support indifferent access for user-provided hashes. The interface is purposefully limited to prevent future use of hash methods that may not work as expected. Refinements are tricky, though, since you lose them whenever they're out of scope (eg, passing a hash to `include?` doesn't call the refinement's `==` method). I initially tried using activesupport's `HashWithIndifferentAccess` but it doesn't work for data hashes because `insert_property_defaults` needs to operate on the actual hash. Requiring all of activesupport just for `HashWithIndifferentAccess` also felt like a pain. The refinement works slightly different from `HashWithIndifferentAccess` because it leaves the keys as whatever type they already are. That might be a little confusing in error objects and `insert_property_defaults` but at least it's consistent with whatever is passed in. Symbol keys are mostly being tested by running the json-schema-test-suite tests again with symbol keys (using `symbolize_names: true` when parsing JSON). I also pulled those tests into their own file and cleaned things up. Addresses: - #91 - #123
This deep stringifies input hashes in order to support symbol (and other non-string) keys. Symbol keys have been a common issue for people forever (as evidenced by `InvalidSymbolKey`) and I've been hesitant to address it because duplicating hashes and stringifying keys hurts performance, but I think it's probably worth it. The tricky thing here is that `insert_property_defaults`, `before_property_validation`, and `after_property_validation` need access to the actual hashes instead of the stringified version. To work around that, the original instance is passed around in `Context` and can be accessed by location using `original_instance`. Values passed in hooks need to be re-stringified in case the user added non-string keys. If this becomes a performance bottleneck, it may make sense to add a way to turn it off for people that know they're using string keys. Related: - #91 - #123
This deep stringifies input hashes in order to support symbol (and other non-string) keys. Symbol keys have been a common issue for people forever (as evidenced by `InvalidSymbolKey`) and I've been hesitant to address it because duplicating hashes and stringifying keys hurts performance, but I think it's probably worth it. The tricky thing here is that `insert_property_defaults`, `before_property_validation`, and `after_property_validation` need access to the actual hashes instead of the stringified version. To work around that, the original instance is passed around in `Context` and can be accessed by location using `original_instance`. Values passed in hooks need to be re-stringified in case the user added non-string keys. If this becomes a performance bottleneck, it may make sense to add a way to turn it off for people that know they're using string keys. Related: - #91 - #123
Features: - Draft 2020-12 support - Draft 2019-09 support - Output formats - Annotations - OpenAPI 3.1 schema support - OpenAPI 3.0 schema support - `insert_property_defaults` in conditional subschemas - Error messages - Non-string schema and data keys See individual commits for more details. Closes: - #27 - #44 - #55 - #91 - #94 - #116 - #123
Features: - Draft 2020-12 support - Draft 2019-09 support - Output formats - Annotations - OpenAPI 3.1 schema support - OpenAPI 3.0 schema support - `insert_property_defaults` in conditional subschemas - Error messages - Non-string schema and data keys See individual commits for more details. Closes: - #27 - #44 - #55 - #91 - #94 - #116 - #123
This deep stringifies input hashes in order to support symbol (and other non-string) keys. Symbol keys have been a common issue for people forever (as evidenced by `InvalidSymbolKey`) and I've been hesitant to address it because duplicating hashes and stringifying keys hurts performance, but I think it's probably worth it. The tricky thing here is that `insert_property_defaults`, `before_property_validation`, and `after_property_validation` need access to the actual hashes instead of the stringified version. To work around that, the original instance is passed around in `Context` and can be accessed by location using `original_instance`. Values passed in hooks need to be re-stringified in case the user added non-string keys. If this becomes a performance bottleneck, it may make sense to add a way to turn it off for people that know they're using string keys. Related: - #91 - #123
Features: - Draft 2020-12 support - Draft 2019-09 support - Output formats - Annotations - OpenAPI 3.1 schema support - OpenAPI 3.0 schema support - `insert_property_defaults` in conditional subschemas - Error messages - Non-string schema and data keys - Schema bundling See individual commits for more details. Closes: - #27 - #44 - #55 - #91 - #94 - #116 - #123 - #136
This deep stringifies input hashes in order to support symbol (and other non-string) keys. Symbol keys have been a common issue for people forever (as evidenced by `InvalidSymbolKey`) and I've been hesitant to address it because duplicating hashes and stringifying keys hurts performance, but I think it's probably worth it. The tricky thing here is that `insert_property_defaults`, `before_property_validation`, and `after_property_validation` need access to the actual hashes instead of the stringified version. To work around that, the original instance is passed around in `Context` and can be accessed by location using `original_instance`. Values passed in hooks need to be re-stringified in case the user added non-string keys. If this becomes a performance bottleneck, it may make sense to add a way to turn it off for people that know they're using string keys. Related: - #91 - #123
Features: - Draft 2020-12 support - Draft 2019-09 support - Output formats - Annotations - OpenAPI 3.1 schema support - OpenAPI 3.0 schema support - `insert_property_defaults` in conditional subschemas - Error messages - Non-string schema and data keys - Schema bundling See individual commits for more details. Closes: - #27 - #44 - #55 - #91 - #94 - #116 - #123 - #136
Released in 2.0.0. Schema keys are deep-stringified to support symbols. Note: symbol values are not supported (eg, |
Currently, parsed JSON with symbolized key fails validation. Please add support for validating JSON with symbolized keys.
The text was updated successfully, but these errors were encountered: