OpenAPI Schema generation stackoverflow when converting Flags enum to a string array & is used in API models with default value #62023
Labels
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
feature-openapi
Milestone
Uh oh!
There was an error while loading. Please reload this page.
Is there an existing issue for this?
Describe the bug
Hi, I'm not 100% sure this is an aspnetcore or a user issue, but it might be a bit of both.
I have a flags enumeration defined like this:
And I want to use it in an API model similarly to this:
To have a better developer experience when using this, I want the client to be able to send flags as arrays of strings, instead of an integer or concatenated string. So Example:
["Flag1", "Flag2"]
instead of"Flag1, Flag2"
.To do this, I created the following JsonConverter below. I've tested this in other places (Kafka (de)serialization, unit tests outputting JSON snapshots), and it works fine.
However, when I want to view my OpenAPI document, it fails to generate, crashing the process with a stack overflow.
Expected Behavior
I would expect the OpenAPI document to generate correctly as outputting an array of enum values. Or at the very least, an array of strings.
Steps To Reproduce
I created a reproducable sample repository here: https://github.com/wsloth/aspnetcore-flagsenum-arrayconverter-issue
It contains both a .NET 9 and a .NET 10 Preview 4 project. They both contain the issue, but it seems like the .NET 9 executable crashes entirely, while the .NET 10 executable keeps running (but does output "stack overflow" in the console).
I was diving into the internals on the .NET 9 version, and saw that it went wrong in
OpenApiJsonSchema
, specifically inReadOpenApiAny
. It would see the array start token, but it had no value at all in the schema (it looked like[ ]
) before reaching the end token.I'm not sure if there should be a value in this array, or if the issue is that if there is a value, it's another instance of the
FlagsEnum
, which enters another (de)serialization loop which generates yet another array.Exceptions (if any)
.NET Version
10.0.100-preview.4.25258.110
Anything else?
No response
The text was updated successfully, but these errors were encountered: