fastify / fast-json-stringify

2x faster than JSON.stringify()
MIT License
3.52k stars 208 forks source link

fix: merged schemas cache key #729

Open DamienVicet opened 5 months ago

DamienVicet commented 5 months ago

Hello, this PR fixes #724.

When diving in the bug, I found that the context.mergedSchemasIds Map, added by @ivan-tymoshenko, is using objects as keys. This caused the schema to infinitely try to build and results into Maximum call stack size exceeded error. So I replaced the key by a hash of the object, then I got another problem : anyOf inside allOf test failed because, to my understanding, we try to cache different merged schemas using the same key in context.mergedSchemasIds (like merged schemas from buildOneOf and from buildAllOf functions).

I am not sure of the solution. Thank you for your review !

ivan-tymoshenko commented 4 months ago

I found the problem. I'm working on the solution. Unfortunatelly merging schemas with recurcive references is the most complecated part of this library and take tons of time every time when we need to fix the bug.