我在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(…)
创建一个片段,专门用于记录超媒体链接。由于您根本不想记录任何链接,因此应避免使用links
代码段。
相反,请修改responseFields
的使用以忽略_links
字段及其下方嵌套的所有内容。 REST Docs将此称为小节,可以使用subsectionWithPath(String)
进行记录。您想忽略subsectionWithPath(String)
小节,因此可以执行以下操作:
_links