You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Example value of an empty OpenApiArray disappears after serialization #1643
The Value property of OpenApiExample is treated as optional and an optional empty IEnumerable is ignored when writing both JSON and YAML. I don't think it's correct, since an empty array or an empty object could be a real example of a response body and we may want to show it to the API's user.
Maggie Kimani (@MaggieKimani1) I believe this is pretty much the only valid scenario here.
My worry is that by changing this condition, we'll have side effects in other places where having empty arrays is not desired.
I suggest doing a couple of things here:
removing the condition, and running unit tests and integration tests for any regression.
evaluating how much work it'd represent to special case this scenario (through a flag/parameter etc...)
Activity
MaggieKimani1 commentedon Aug 1, 2024
I'm still struggling to see the value of writing out empty collection values as this seems to be by design(subject to change) in the lib.
OpenAPI.NET/src/Microsoft.OpenApi/Writers/OpenApiWriterExtensions.cs
Lines 146 to 149 in b274162
Required objects are still written out even when empty.
Vincent Biret (@baywet) what do you think?
CarlosZaldivar2 commentedon Aug 1, 2024
Maggie Kimani (@MaggieKimani1) How can I show an empty array as a valid response example, when the library removes the empty array?
baywet commentedon Aug 1, 2024
Maggie Kimani (@MaggieKimani1) I believe this is pretty much the only valid scenario here.
My worry is that by changing this condition, we'll have side effects in other places where having empty arrays is not desired.
I suggest doing a couple of things here: