davishmcclurg / json_schemer

JSON Schema validator. Supports drafts 4, 6, 7, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1.
MIT License
408 stars 64 forks source link

Compare property default instance locations by id #180

Closed davishmcclurg closed 8 months ago

davishmcclurg commented 8 months ago

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:

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: https://github.com/davishmcclurg/json_schemer/issues/179