0

我现在正在使用 spring rest docs,我收到下一个错误:

"org.springframework.restdocs.snippet.SnippetException: Cannot document response fields as the response body is empty"

事实上,当我调试测试时,我已经看到内容是空的。这是我的测试:

@Test
    @Throws(Exception::class)
    fun shouldReturnDefaultMessage() {
        val paramsMock = mapOf("swid" to "asudyasd-asdasd-asdasd", "seeAll" to true)

        `when`(apiRequest.parameters).thenReturn(paramsMock)
        `when`(browsePlayerServiceRepresentable.getEntitiesBrowse(anyObject())).thenReturn(Single.just(presentBrowsePlayers()))
        this.mockMvc!!.perform(get("/v1/browse/players").flashAttr("apiRequest", apiRequest)
                .accept(MediaType.APPLICATION_JSON)
        ).andDo(document("home", preprocessRequest(),
                preprocessResponse(prettyPrint()), relaxedResponseFields(
                fieldWithPath("id")
                        .description("ID of the team."),
                fieldWithPath("name")
                        .description("Name of the team."),
                fieldWithPath("members")
                        .description("Empty list of team members.")
        )))
    }

这是我从调试中得到的:

在此处输入图像描述

但我可以在模型和视图端看到我的模拟响应信息:

在此处输入图像描述

我的控制器方法返回一个对象,就像:

在此处输入图像描述

并且由于某种原因,框架没有正确地进行映射,知道是否可以将此信息设置为内容响应,或者我是否可以创建一个自定义的 FieldDescriptor 来面对这种情况?

谢谢

4

0 回答 0