Reputation: 2979
I have a springBoot 2.1.9.RELEASE application that uses Spring REST Docs.
I have this payload
{
"hostel" : [ {
"bookingHostelIdentifier" : {
"internalMasterIdentifier" : {
"id" : "987654321"
}
}
}, {
"bookingHostelIdentifier" : {
"customerIdentifier" : {
"id" : "23456789"
}
}
}, {
"bookingHostelIdentifier" : {
"internalMasterIdentifier" : {
"id" : "87654321"
}
}
} ]
}
which I documented like this
fieldWithPath("hostel[]").description("The list of hostels"),
fieldWithPath("hostel[].name").description("The list of hostels"),
fieldWithPath("hostel[].bookingHostelIdentifier").description("The list of hostels"),
fieldWithPath("hostel[].bookingHostelIdentifier.internalMasterIdentifier.id").description("The list of hostels"),
fieldWithPath("hostel[].bookingHostelIdentifier.customerIdentifier.id").description("The list of hostels")
but I got this Exception
org.springframework.restdocs.snippet.SnippetException:
Fields with the following paths were not found in the payload:
[hostel[].bookingHostelIdentifier.internalMasterIdentifier.id, hostel[].bookingHostelIdentifier.customerIdentifier.id]
Upvotes: 0
Views: 337
Reputation: 116051
As the internalMasterIdentifier
and the customerIdentifier
fields are not always present in a bookingHostelIdentifier
, you should mark those fields or the id
fields that are nested beneath them as optional.
fieldWithPath("hostel[].bookingHostelIdentifier.internalMasterIdentifier.id").optional().description("The list of hostels"),
fieldWithPath("hostel[].bookingHostelIdentifier.customerIdentifier.id").optional().description("The list of hostels")
Upvotes: 1