-
Notifications
You must be signed in to change notification settings - Fork 10.3k
openapi with newtonsoft.json suppport generate incorrect request/response model schema #60458
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
Microsoft.AspNetCore.OpenApi doesn't support Newtonsoft.Json because it is built on top of the JSON schema support in System.Text.Json. It also supports native AoT, which Newtonsoft.Json is not compatible with. If you wish to use the new OpenAPI support with MVC you'll need to either migrate to System.Text.Json, or double-annotate/configure all your models so you get equivalent behaviour from both JSON implementations. |
@martincostello Newtonsfot.Json and S.T.J have many difference , and can I switch the "JsonSchemaService" with a Newtonsoft.Json version in DI ? |
I don't think you can because it's fundamentally built on top of features added to System.Text.Json for .NET 9. |
If you need Newtonsoft.Json support, use NSwag or Swashbuckle to generate OpenAPI documents. |
It does yes, because it has better performance than Newtonsoft.Json and async support. And it's a lot of work to maintain two implementations to allow for it, and there isn't 100% parity between them. I highly doubt Microsoft.AspNetCore.OpenApi will support it for the reasons I've already outlined, and if it did you'd have to wait until at least .NET 10 to do so. A better investment of your time would be to move to System.Text.Json to improve the performance of your system as a whole. Otherwise you'll need to use one of the other suggested libraries to produce OpenAPI documents. |
Further, Microsoft.AspNetCore.OpenApi depends on Microsoft.OpenApi, which itself is built on top of System.Text.Json for v2 that .NET 10 will depend on, so I think that makes it effectively impossible for it to support Newtonsoft.Json without re-implementing everything a second time. |
@John0King Thanks for filing this issue! As @martincostello mentioned, the M.A.OpenApi package builds on-top of System.Text.Json and I don't anticipate that we'll be supporting another serializer out of the box in the future. With that said, the closest analogy to the code that you posted here is creating a copy of your Newtonsoft.Json serializer settings and passing them to the
|
I'm still using IMO currently
and the reason for continue to use newtonsoft.json instead of S.T.J is
|
It will be part of .NET 10 preview 2: #39927 (comment)
Can you elaborate? This should be supported via
If it's custom then by definition it's not built-in. What exactly are you trying to do?
If that's the case, then I suggest opening an API suggestion in the dotnet/runtime repository to add such support. There's plenty of time for such a feature to land in .NET 10 if it was approved. |
This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes. See our Issue Management Policies for more information. |
Is there an existing issue for this?
Describe the bug
when using OpenAPI from Microsoft and Newtonsoft.json , it still use System.Text.Json to generated OpenApi document , that cause the request/response model's json schema be incorrect.
Expected Behavior
expect to generate the model
Foo
has aNewtonName
property.Steps To Reproduce
Exceptions (if any)
No response
.NET Version
9.0.200
Anything else?
No response
The text was updated successfully, but these errors were encountered: