spring-projects / spring-restdocs

Test-driven documentation for RESTful services
https://spring.io/projects/spring-restdocs
Apache License 2.0
1.16k stars 735 forks source link

Support array indices in JSON field paths #468

Open mariusoe opened 6 years ago

mariusoe commented 6 years ago

Hi,

when using a PayloadSubsectionExtractor (e.g. FieldPathPayloadSubsectionExtractor) to extract a subsection of a JSON payload, array indices are ignored.

I would assume that when a path is used like Outer[].Nested[0].Attribute only the first (in this example Nested) element or which is matching the specified index will match the given path and, thus, returned. But it extracts always all elements which results in a PayloadHandlingException({PATH} + " does not uniquely identify a subsection of the payload").

wilkinsona commented 6 years ago

That's working as (currently) designed. There's no support for array indices anywhere in REST Docs at the moment.

dibog commented 4 years ago

+1 from me for the enhancement request

florensie commented 1 week ago

If it's not supported, it shouldn't be parsed either. Currently it's possible to use path.to.array[0] and the index will be ignored, creating confusing results.