我有一个响应,它是一个 json 数组。每个元素都有它的意义,我可以描述它。
我的阵列:
["1525032694","300","true"]
我在文档中找到了一个示例,该示例描述了一个数组和每个相同的元素:
https://docs.spring.io/spring-restdocs/docs/current/reference/html5/#documenting-your-api-request-response-payloads-fields-reusing-field-descriptors
但我想知道如何将其描述为:
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"))
))
最佳答案
好的,它变得相当容易:
responseFields(
fieldWithPath("[0]").description("Current timestamp"),
fieldWithPath("[1]").description("Device mode"),
fieldWithPath("[2]").description("Device parameter")
),
关于arrays - 使用 spring-restdocs 记录数组的每个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50090870/