Skip to content
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

Improve beneathPath to work with multiple nested arrays #569

Open
Jeff-Walker opened this issue Dec 12, 2018 · 1 comment
Open

Improve beneathPath to work with multiple nested arrays #569

Jeff-Walker opened this issue Dec 12, 2018 · 1 comment

Comments

@Jeff-Walker
Copy link

In beneathPath(), paths with an array work now, thanks to #473 and 9e1ba8a. But I'm still having a problem with arrays when there are two levels of arrays in the payload.
Consider the payload:

{
  "roles": [
    {
      "key": "1",
      "name": "one",
      "more": [
        {
          "id": 1
        }
      ]
    },
    {
      "key": "1",
      "name": "one",
      "more": []
    }
  ]
}

And I document it like so:

document(snippetName,
        responseFields(
            // beneathPath understands that roles is an array and does the right thing
            beneathPath("roles").withSubsectionId("roles"), 
            fieldWithPath("key").description("key"),
            fieldWithPath("name").description("name"),
            subsectionWithPath("more").description("array")));

This will give me the fields of roles with a description of the more property. To then document the object within the more array, I do a separate snippet:

document(snippetName,
        responseFields(
            // now beneathPath doesn't deal with 'roles' here like it does above
            beneathPath("roles[].more").withSubsectionId("more"), 
            fieldWithPath("[].id").description("id")));

The issue here is that at this point, the second array, the problem is the same as #473, you get a snippet with [] in front of the field path, which is functional, but not great from a documentation standpoint, which is the whole point.

To make this work like the single array, I'd expect maybe beneathPath("roles.more") to work with fieldWithPath("id"), giving me a table with Paths like id in this case.

@nladygin
Copy link

nladygin commented Aug 5, 2020

Hi
got the same problem with a similar response structure
root
|

  • attr:[]
    |
    • attr:[]
      |
      • attr

Works with beneathPath("attr[].attr") and "[].attr" only, but looks a little bit ugly in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants