Open manifestori opened 7 months ago
Hey 👋 thanks a lot for opening this issue and using the library. I am not super familiar with the more complicated cases of gjson syntax, I have only used the simple examples.
So for me to understand the issue with #.arr.#.id
where doesn't iterrate through all the items? does this happen only for double nested? or triple nested? What was your idea for handling this in go-snaps level?
Hey @gkampitakis it doesn't matter if it's double or triple. If you use # more than once, you get a false positive match and the snapshot will yield just a <Any value>
result. (unusable snapshot).
My idea was to parse the path before passing it to gjson. Breaking it down to multiple calls to gjson (instead of 1 call with #.prop.#.id), pass n times 0...n.prop.# to gjson and merge result (recursively)
this should be fixed on Jason, but maybe it's an easier workaround to implement.
Hey 👋 I am not sure how much I want to add this fix in go-snaps
😞
Description
When trying to this library with a complex json. for example:
Attempting to
match.Any("#.components.#.properties.value")
yields a bad snapshot. modifying tomatch.Any("0.components.#.properties.value")
yields a good but incomplete matched snapshot.A solution for prerendering the matchers based on the input is non-functional. (creating a matcher per nested of nested matcher).
It's probably due to limitations with gjson - https://github.com/tidwall/gjson/issues/267 As you figured, snapshots can be (and probably are) complex, nested arrays within an array is very common, this yields using a snapshot almost useless.
We can try fixing it ourselves, parsing the '.#.' and running through a loop with '.0.' ... '.n.' new matchers to workaround this. wdyt?
Steps to Reproduce
Run with attached JSON (or simplified version) or any [{ ... , arr: [ { id: 123 } ]}] with a "#.arr.#.id" matcher.
Expected Behavior
No response