arrays - 使用 spring-restdocs 记录数组的每个元素

标签 arrays json kotlin spring-restdocs

我有一个响应,它是一个 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/

相关文章:

c# - 如何添加 net5.0 Worker 应用程序 AddJsonOptions

python - 按子字符串聚合 json 元素

java - 如何按一定顺序打印 3 个不同字符串数组的元素?

javascript - 基于For循环迭代的数组拼接

arrays - 如何快速获取二维数组中的第一个维度

php - jQuery $.post 处理 JSON 响应

kotlin - 如何使 "inappropriate blocking method call"合适?

android - BigDecimal.doubleValue 不存在?

android - CoroutineScope的范围是什么?

java - 从数组中减去不起作用