-
Notifications
You must be signed in to change notification settings - Fork 10.4k
.NET 9 OpenApi: JSON schema generation is not supported for contracts using ReferenceHandler.Preserve #58943
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
@nicolaiarocci Thanks for filing this issue! @eiriktsarpalis Is there a particular reason we opted not to generate schemas when It seems like the schemas that Swashbuckle creates ignore the ReferenceHandler setting altogether:
for:
|
Reference preservation alters the schema for most types, notably with collections that end up wrapping their values in JSON objects. Support for it was cut in .NET 9 for lack of time, but it's conceivable that it could be added in the future provided there is demand. |
I should add that enabling reference preservation in your app carries important security ramifications. It should only be used with trusted inputs produced by System.Text.Json. In my opinion, it is not appropriate to use reference preservation in the context of web apps or Open API. |
Helo @eiriktsarpalis I haven't understood well, I have that same error but also this one: Could you help me understand why this happens and how to avoid it? |
This looks like a different error. Could you file an issue in dotnet/runtime with a standalone reproduction? Thanks. |
Is there an existing issue for this?
Describe the bug
Upgrading a .NET 8 Minimal API to .NET 9 and switching from Swashbuckle.AspNetCore to built-in Open API support, we get the following exception:
System.NotSupportedException: JSON schema generation is not supported for contracts using ReferenceHandler.Preserve.
Indeed, we have references preserved in our JSON options:
By commenting out the
ReferenceHandler.Preserve
, the open api document is created as expected.Expected Behavior
Support for contracts using ReferenceHandler.Preserve.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
9.0.100
Anything else?
No response
The text was updated successfully, but these errors were encountered: