Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Fleshgrinder opened this issue Apr 24, 2018 · 2 comments

Comments

@Fleshgrinder
Copy link

Fleshgrinder commented Apr 24, 2018

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?
@wilkinsona
Copy link
Member

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 wilkinsona changed the title How to document array element types? Allow the type of an array's scalar elements to be documented and enforced Apr 24, 2018
@Fleshgrinder
Copy link
Author

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. 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants