-
Notifications
You must be signed in to change notification settings - Fork 64
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
Some properties with default values not inserted #179
Comments
The keys used to collect property defaults are mutable hashes, which causes weird hash table problems when they're modified (`#hash` no longer matches even though they have the same `#object_id`). Explained here: https://docs.ruby-lang.org/en/3.3/Hash.html#class-Hash-label-Modifying+an+Active+Hash+Key I think this problem got covered up a bit because it requires more than 8 keys for values to be dropped. `compare_by_identity` fixes things by just using `#object_id` to compare hash keys. It stays consistent after the hash key is mutated. From the [docs][0]: > Note: this requirement does not apply if the Hash uses > `compare_by_identity` since comparison will then rely on the keys' > object id instead of `hash` and `eql?`. Fixes: #179 [0]: https://docs.ruby-lang.org/en/3.3/Hash.html#class-Hash-label-User-Defined+Hash+Keys
Hi @IsmoKarkkainen! Thanks for opening this—it's a strange one. I think I found the problem and the fix: #180 |
Happy to try it out. I changed the test script and the code that originally showed the problem with real schema and data to require_relative the json_schemer/lib/json_schemer in the new branch. Test script still shows the issue but in the original code one case of missing property with default was fixed. Another one in there remains. |
You might be getting the wrong code since require 'json'
require 'json_schemer' With: require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'json'
gem 'json_schemer', path: '/path/to/json_schemer/repo/with/branch/checked/out'
end Pulling directly from github also works, but it's slower to run: gem 'json_schemer', git: 'https://github.com/davishmcclurg/json_schemer', branch: 'compare-instance-locations-by-identity' |
Ok, now the fields are present as the script does not complain and the real case has all omitted fields with defaults in place as well. Works. Thank you. |
Using insert_property_defaults results in some properties with defaults not being inserted. The attached txt file
defaults_issue.txt
is a ruby script that demonstrates the issue. Save and rename to defaults_issue.rb and run. (Attaching rb file was not allowed, hence renamed.)
There are probably other variations that produce something odd. I originally had meta_schema: 'https://spec.openapis.org/oas/3.1/dialect/base' but dropped that when simplifying the schema and data.
Ruby version 3.1.2, json_schemer 2.2.0.
The text was updated successfully, but these errors were encountered: