Skip to content

responseFields beneathPath array in array #702

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

Closed
DriesCleymans opened this issue Nov 5, 2020 · 1 comment
Closed

responseFields beneathPath array in array #702

DriesCleymans opened this issue Nov 5, 2020 · 1 comment
Labels
status: duplicate Duplicate of another issue type: enhancement Enhancement that adds a new feature

Comments

@DriesCleymans
Copy link

I have a response with an array of objects, each objects contains a property with another array. It looks like this:

[ {
  "id" : 1,
  "name" : "Quick start",
  "type" : "radio",
  "musicChannels" : [ {
    "id" : 134,
    "name" : "Popular & Nostalgic",
    "musicChannelGroupId" : 1,
    "musicCollections" : "An array of MusicCollections"
  }, {
    "id" : 146,
    "name" : "Young & Alternative",
    "musicChannelGroupId" : 1,
    "musicCollections" : "An array of MusicCollections"
  } ]
}, {
  "id" : 2,
  "name" : "Create mood",
  "type" : "radio",
  "musicChannels" : [ {
    "id" : 146,
    "name" : "Popular & Nostalgic",
    "musicChannelGroupId" : 2,
    "musicCollections" : "An array of MusicCollections"
  } ]
}, {
  "id" : 3,
  "name" : "Discover more",
  "type" : "radio",
  "musicChannels" : [ {
    "id" : 146,
    "name" : "Young & Alternative",
    "musicChannelGroupId" : 3,
    "musicCollections" : "An array of MusicCollections"
  } ]
} ]

I want to document the object in the second array, and to generate a code snippet with restDocs, I am trying this:

responseBody(
	beneathPath("[0].musicChannels.[0]").withSubsectionId("musicChannel2")
)

But the output is:

[ {
  "id" : 134,
  "name" : "Popular & Nostalgic",
  "musicChannelGroupId" : 1,
  "musicCollections" : "An array of MusicCollections"
}, {
  "id" : 146,
  "name" : "Young & Alternative",
  "musicChannelGroupId" : 1,
  "musicCollections" : "An array of MusicCollections"
} ]

I want to have only the first object in the response body, but i fail with whatever I try to insert into 'beneathPath'.

So the question is: How to get the body for the first element in the array of a property in the first element in an array. I want this as a result:

{
  "id" : 134,
  "name" : "Popular & Nostalgic",
  "musicChannelGroupId" : 1,
  "musicCollections" : "An array of MusicCollections"
}
@wilkinsona
Copy link
Member

Unfortunately, there's no support at the moment for specifying a specific index when drilling down into an array. #468 is tracking that enhancement.

@wilkinsona wilkinsona added status: duplicate Duplicate of another issue type: enhancement Enhancement that adds a new feature and removed status: waiting-for-triage Untriaged issue labels Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate Duplicate of another issue type: enhancement Enhancement that adds a new feature
Projects
None yet
Development

No branches or pull requests

3 participants