【发布时间】:2018-04-29 20:14:56
【问题描述】:
我的响应是一个 json 数组。每个元素都有它的含义,我可以描述它。
我的数组:
["1525032694","300","true"]
我在文档中找到了一个示例,该示例描述了一个数组和每个相同的元素:
但我想知道如何将其描述为:
current timestamp、seconds to next measurement、should perform fota
我目前的测试:
webTestClient.post().uri("/api//measurement/${SampleData.deviceId}")
.syncBody(SampleData.sampleMeasurement())
.exchange()
.expectStatus()
.isOk
.expectBody()
.consumeWith(document("add-measurement", responseFields(
fieldWithPath("[]")
.description("An array of device settings"))
))
【问题讨论】:
-
我没有使用过 spring-restdocs。
fieldWithPath("0").description("current timestamp")有效吗?在 JavaScript 中,每个数组元素都可以像使用"0"、"1"、"2"、...、"${n}"... 的任何其他属性一样访问,但这不是 JavaScript。 :-) 如果"0"不起作用,我想知道"[0]"是否起作用...... -
您可以控制 API 响应吗?为什么不返回正确的对象而不是设备设置的数组?
-
不幸的是我无法控制这一点,这就是为什么我需要更准确地记录响应
标签: arrays json kotlin spring-restdocs