4

I'm having a response which is an json array. Each element has it's meaning and I would be able to describe it.

My array:

["1525032694","300","true"]

I've found an example in the documentation that describes an array and each element which is the same:

https://docs.spring.io/spring-restdocs/docs/current/reference/html5/#documenting-your-api-request-response-payloads-fields-reusing-field-descriptors

But I would like to know how I can describe each of it as:

current timestamp, seconds to next measurement, should perform fota

My current test:

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"))
        ))
Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
pixel
  • 24,905
  • 36
  • 149
  • 251
  • I've not used spring-restdocs. Does `fieldWithPath("0").description("current timestamp")` work? In JavaScript each array element is accessible like any other property using `"0"`, `"1"`, `"2"`, ..., `"${n}"`... but this isn't JavaScript. :-) If `"0"` doesn't work I wonder if `"[0]"` works... – mfulton26 May 08 '18 at 16:18
  • 1
    Do you have control of the API response? Why don't you return a proper object instead of an array with the device settings? – Pedro Tavares May 09 '18 at 10:57
  • Unfortunately I can't control this, that's why I need to document response even more precisely – pixel May 09 '18 at 11:00

1 Answers1

0

Ok, it turns that be fairly easy:

        responseFields(
            fieldWithPath("[0]").description("Current timestamp"),
            fieldWithPath("[1]").description("Device mode"),
            fieldWithPath("[2]").description("Device parameter")
        ),
pixel
  • 24,905
  • 36
  • 149
  • 251