Spring boot SpringREST文档-避免文档链接

Spring boot SpringREST文档-避免文档链接,spring-boot,spring-mvc,spring-hateoas,hateoas,spring-restdocs,Spring Boot,Spring Mvc,Spring Hateoas,Hateoas,Spring Restdocs,我在SpringBoot 2应用程序中使用了此方法: @Test public void shouldEchoTheParameter() throws Exception { mockMvc.perform(get("/echo").param("echoMessage", "Test")) .andExpect(status().isOk()) .andExpect(jsonPath("$.message", is("Test"))) .andDo(document("echo-exampl

我在SpringBoot 2应用程序中使用了此方法:

@Test
public void shouldEchoTheParameter() throws Exception {
mockMvc.perform(get("/echo").param("echoMessage", "Test"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message", is("Test")))
.andDo(document("echo-example",
preprocessResponse(prettyPrint()),
links(linkWithRel("self").ignored().optional()),
requestParameters(
parameterWithName("echoMessage").description("The message to be echoed")),
responseFields(
fieldWithPath("message").
description("The message echoed"))
));
}
我希望避免记录有效负载的这一部分:

{
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/echo"
    }
  }
}
我包括:

links(linkWithRel("self").ignored().optional()),
但我有一个错误:

java.lang.IllegalStateException: No LinkExtractor has been provided and one is not available for the content type application/vnd.pxs.echo.v1+json;charset=UTF-8
links(…)
创建一个专门用于记录超媒体链接的片段。由于您根本不想记录任何链接,因此应避免使用
链接
代码段

相反,请修改
响应字段的使用,以忽略
\u链接
字段及其下嵌套的所有内容。REST文档将其称为一个小节,可以使用。您想忽略
\u链接
小节,因此可以执行以下操作:

responseFields(subsectionWithPath("_links").ignored(),     
    fieldWithPath("message").description("The message echoed"))

您想记录一些链接,而不是
self
链接,还是根本不记录任何链接?根本不记录任何链接