spring-restdocs icon indicating copy to clipboard operation
spring-restdocs copied to clipboard

Allow the type of an array's scalar elements to be documented and enforced

Open Fleshgrinder opened this issue 6 years ago • 2 comments

Not sure if this is the right place to ask this question but maybe it directly translates to a feature request. Let our payload be as follows:

{
    "data": [
        "1",
        "2",
        "3",
        "…",
        "n"
    ]
}

We can easily document the data property with the following code:

responseFields(fieldWithPath("data").type(JsonFieldType.ARRAY))

We know that every element is of type string and it is guaranteed that each element will be of type string; none of the following approaches work:

fieldWithPath("data.*").type(JsonFieldType.STRING)
fieldWithPath("data[].").type(JsonFieldType.STRING)
fieldWithPath("data[].*").type(JsonFieldType.STRING)
  • Is there a possibility to document the type?
  • What is your intended way to document something like this?

Fleshgrinder avatar Apr 24 '18 15:04 Fleshgrinder

Is there a possibility to document the type?

Not at the moment, at least not in a way that would cause REST Docs to enforce that each element in the array is of a particular scalar type.

What is your intended way to document something like this?

Right now, I'd just document it in the description. Something like, "An array of Strings that … ".

wilkinsona avatar Apr 24 '18 16:04 wilkinsona

Many thanks for the very fast response. Your proposed workaround is exactly what we are doing now but having first-level support for this would be awesome. Many thanks for considering it. I might have a stab at it myself and provide a PR if I find the time. 😀

Fleshgrinder avatar Apr 24 '18 17:04 Fleshgrinder