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
ASP.NET Core 3 support #1961
Comments
Usually this is added when the new library is RTM. As a ref, here are the PRs for adding 2.2 support: |
You may want to start looking into this now using the previews, as changes to remove Newtonsoft.Json as a core dependency of MVC in ASP.NET Core 3.0 will likely break compatibility and cause a blocker for people from upgrading due to usage of Related issues: |
Yep, this will be a major change, mainly in the NJsonSchema repo. Until now, noone could tell me what the replacement of newtonsoft’s contract resolver is... |
So if you want to keep a dependency on Newtonsoft.Json, you'd use Ultimately, the problematic reference for 3.0 is |
When using the newtonsoft.json serializer it should be no big issue - my problem is more with the new serializer and how to get the serialization contract there... |
Having had a quick look at the code, a "fast" way to do this (though still a breaking change) would be to remove all usage of Otherwise you're looking at having to come up with some sort of abstraction on to get the serializer settings, abstract away JSON serialization completely like MVC is doing, or start forking the code with things like hash defines to handle different code and serialization paths for different TFMs. |
Have also opened dotnet/aspnetcore#8254 suggesting |
I think we could just add the new target framework .net core 3 to nswag.aspnetcore and use the new MvcNewtonsoftJsonOptions with conditional compile... the downside is that you cannot use asp.net core 2.2 on .net core 3.0 - to allow that we’d need a new package - e.g. nswag.aspnetcore3 - i.e. decouple the aspnetcore version from the target framework version. But this means potentially a new package for every “major” aspnetcore version - a maintainability nightmare |
That approach also has the downside of forcing the Newtonsoft.Json version of MVC JSON formatting to be active even if the user isn't using it, rather than the new native implementation if someone wants to go with that instead. Hopefully the ASP.NET Core team can come up with something to make this less painful to manage. |
Yeah, but we would only use these options if they are registered, ie the newtonsoft json serializer is active -otherwise we would use the new implementation. But i dont know at all how the contract reflection works there... |
And of course the new serializer requires a lot of work because ATM everything is newtonsoft.json based - ie at the beginning nswag will only work with aspnetcore 3 WITH the newtonsoft serializer (or some [automatic] newtonsoft settings which more or less resemble the new serializer behavior) |
Does anyone know a workaround/hack that i can use today while we wait for a proper fix? |
Using preview 3.0, there is currently no workaround. |
So the problem is only that MvcJsonOptions has been renamed to MvcNewtonsoftJsonOptions? |
It’s not just been renamed, but also moved to a different assembly, so it’s a complete breaking change as the types this library are compiled against aren’t there at runtime, effectively making everything unusable. The only current solution is to fork this repo, swap to the new type from 3.0, compile it yourself and use that. |
Yes, but assuming they to this type forward thing, will it work even if NSwag targets the "old" ASP.NET Core 2.2 version? |
If they come up with a solution then this issue can just be closed as it’ll no longer be an issue and it’ll “just work”, but looking at their reply it doesn’t look like a simple fix, but they seem to be treating it as high priority to resolve. |
PR for supporting ASP.NET Core 3: #2041 |
Ok, the NSwag.AspNetCore package should now (v12.0.20) work with the ASP.NET Core 3 preview... Keeping the PR open as this (conditionals & Core 3 TFM) is probably the way to go - also we need many more changes to support CLI etc... For now probably only the ASP.NET Core middleware works. Please report any problems. @pranavkm Does this dynamic fallback look good (for now)? |
Yeah, that seems reasonable. If you have builds available with the change, I'd be happy to check the swagger gen works with the most recent preview4 bits of AspNetCore. |
@pranavkm this is available in v12.0.20 - I tested it with preview3 |
NSwag.MSBuild needs to be updated to support .NET Core 3.0. Generic Host support, and and adding NSwagExe_Core30. |
Yes, but i wanted to wait until core 3 is released :-) not an option? |
Aah. I understand. I don’t know how hard it is to add, but a preview would be nice. |
I agree that it would be nice... I saw the following problems:
But ill see again if its worth the effort now... |
What is the progress? |
NSwag.AspNetCore (the middlewares) should work with ASP.NET Core 3.0, the CLI binaries (e.g. NSwag.MSbuild, NSwag.ConsoleCore) are currently not released with .NET Core 3.0 target framework and ASP.NET Core 3.0 dependencies because it would force all maintainers to install .NET Core 3.0 previews, etc. - waiting for a RC for now. |
Hi @RicoSuter, You have written, that the middlewares should work with ASP.NET Core 3.0. Unfortunatelly, I can't download the swagger document. I got error 404 (Not Found). I tried on preview7 and preview5. Here is my Startup.cs `public Startup(IConfiguration configuration)
` Is there any chance to use NSwag in ASP.NET Core 3.0, or currently I have to move back to 2.2? |
Have you tried to add it before UseRouting()? |
@Oposow You probably need to add Newtonsoft Json support. It is how I solved it on my project and I get it working with preview 7. |
Hi, thank you very much for answers. I will test it at work on monday :-)
sob., 27 lip 2019, 01:53 użytkownik Valentin Fritz <notifications@github.com>
napisał:
… @Oposow <https://github.com/Oposow> You probably need to add Newtonsoft
Json support.
Include the Microsoft.AspNetCore.Mvc.NewtonsoftJson nuget package in
preview version and add .AddNewtonsoftJson() after
services.AddControllers()
It is how I solved it and I get it working with preview 7.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1961?email_source=notifications&email_token=AFSNH3YNZ4JL575IWLKS6U3QBOE7ZA5CNFSM4GXYVUK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD256SMY#issuecomment-515631411>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFSNH3ZJWZITMBXAMKSPWG3QBOE7ZANCNFSM4GXYVUKQ>
.
|
@RicoSuter unfortunatelly changing the methods calling order didn't help. The solution provided by @vfrz worked perfectly, thank you very much! |
Word on the street is there it may go straight from preview 8 to release, no RC's version. September 23rd at .Net Conf. As an aside for those switching their implementation to the new native JSON support, and not planning to use the old Newtonsoft JSON libraries, how will this work with Nswag? |
Unless things have changed very recently, last I was aware, there was going to be a preview 9 before the final version ships during .NET Conf: https://github.com/dotnet/corefx/issues/39769#issuecomment-518766445 |
I think it will be possible to only use newtonsoft contract resolver internally and use the new json stuff for serialization... then obly the internal resolver needs to be aligned with the actual serializer |
Added fallback to JsonSerializerSettings from OpenAPI document settings if settings are not provided by calling AddNewtonsoftJson(). v13.0.6 |
So we wont get any MSBuild task for 3.0 before the actual release? |
Maybe you can already use this instead of CLI? |
|
Hi @RicoSuter |
I hope to find time to look into this this week... |
Release v13.1.0: #2427 Also supports NRT (provided by Namotion.Reflection/): .NET Core 3.0 support docs: https://github.com/RicoSuter/NSwag/wiki/AspNetCoreOpenApiDocumentGenerator#net-core-3-and-c-8 Please report if something is not working as expected. |
Works great, thank you. Implemented here; |
This is the solution: #1961 (comment). |
Does not work for me |
Where is the ASP.NET Core 3 support?
The text was updated successfully, but these errors were encountered: