restdocs SnippetException due to HAL "_links" elements from spring-data-rest
Seems like the _links are always going to have that self-reference back to the same entity, right?
Yes, that's right.
I may have your solution for ignoring some links in a small github sample. Especially the part:
mockMvc.perform(RestDocumentationRequestBuilders.get(beerLocation)).andExpect(status().isOk())
.andDo(document("beer-get", links(
linkWithRel("self").ignored(),
linkWithRel("beerapi:beer").description("The <<beers, Beer resource>> itself"),
linkWithRel("curies").ignored()
),
responseFields(
fieldWithPath("name").description("The name of the tasty fresh liquid"),
fieldWithPath("_links").description("<<beer-links,Links>> to other resources")
)
));
where I completely ignore all "generated" fields and only create a documentation entry for the domain. Your item
link would be my beerapi:beer
.
I really don't know what is best practice here, but I would always document as much as possible since you can use asciidoctor links (like <<beer-links,Links>>
) wherever possible to reference other parts with more documentation.