-
Notifications
You must be signed in to change notification settings - Fork 737
A required field cannot be absent when nested beneath an optional empty array #519
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
Comments
I'm a bit hazy about whether But conceptually I think the issue should still make sense even without the |
Thanks. This isn't a regression of #429 but a situation that wasn't considered when it was fixed. Your expectation is that an array field that contains an empty array will be treated as if it is absent. REST Docs currently treats it as being present. Because |
Thank you! |
I'm sorry to reopen this, but I can't get it to work. I've double-checked that I'm using a version with the commits from this GitHub issue incorporated. Here's my real-world usecase. I'm getting this error:
My descriptors look like this: val inlineGdprArray: FieldDescriptor =
fieldWithPath("data[].inlineGdpr")
.type(JsonFieldType.ARRAY)
val inlineGdprRow: FieldDescriptor =
fieldWithPath("data[].inlineGdpr[]")
.type(JsonFieldType.OBJECT)
.optional()
val inlineGdprId: FieldDescriptor =
fieldWithPath("data[].inlineGdpr[].id")
.type(JsonFieldType.NUMBER)
.description("ID of the GDPR entry") Relevant parts of the JSON I'm testing this against: {
"data": [
{
"inlineGdpr": []
}
]
} Maybe it has to do with nested arrays, ie. the |
Thanks for testing a snapshot.
That appears to be exactly it. There being two arrays involved means that REST Docs finds a list that contains a single empty list. It doesn't consider that to be empty so it incorrectly doesn't consider the field to be missing. As a result the |
Thank you, can confirm it works now. |
Excellent. Thanks for trying a snapshot again. It's very timely as I want to release 1.2.5 and 2.0.2 later today or tomorrow. |
This is a regression of #429, tested with both the
2.0.2.BUILD-SNAPSHOT
and2.0.1.RELEASE
.I've created an example project at https://github.com/Janiczek/restdocs-429-regression
Stacktrace after ./gradlew test
The JSON that fails:
{ "outer": [] }
The idea is that there's a required
outer
field with an array, inside which are optional objects that, if present, contain a requiredinner
field with a number.The response fields:
The text was updated successfully, but these errors were encountered: