domaindrivendev / Swashbuckle.AspNetCore

Swagger tools for documenting API's built on ASP.NET Core
MIT License
5.25k stars 1.31k forks source link

newtonsoft serializer settings is not respected #1546

Closed aeb-dev closed 4 years ago

aeb-dev commented 4 years ago

Swashbuckle does not respect newtonsoft serializer setting on .net core 3.1 because of the following line:

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/6fd662b7e1f1a9920dcd5a0f5d71bbe8f0c76187/src/Swashbuckle.AspNetCore.Newtonsoft/DependencyInjection/NewtonsoftServiceCollectionExtensions.cs#L27

it should be:

#if NETCOREAPP3_0 || NETCOREAPP3_1
orphisAG commented 4 years ago

Is there any estimate when this will get updated ? :-)

domaindrivendev commented 4 years ago

NETCOREAPP3_0 is a compile-time const to support multi-targeting during the Swashbuckle build process. It currently targets netstandard2.0 and netcoreapp3.0, and the latter will work with a 3.1 application without any problem. So, I highly doubt this is the root cause of the problem.

I would say your issue is most likely a dup of #1459. TL;DR this version defaults to honoring System.Text.Json (as opposed to Newtonsoft) serializer behavior. You need to expicitly opt-in to honoring Newtonsoft as described in the readme:

https://github.com/domaindrivendev/Swashbuckle.AspNetCore#systemtextjson-stj-vs-newtonsoft

aeb-dev commented 4 years ago

Can you reevaluate your evaluation please, although I do not remember the details of my test, I have tried with downgrading my app 3.0 to test and it worked. However when I have changed backed 3.1 the options were not respected.

As you have said NETCOREAPP3_0 is compile time, when I compile with 3.1 #if part will be discarded because it will evaluate to false.

the output will be different based on systems sdk(3.0, 3.1 etc.)

I understood what you are trying to say, probably you are right, but I do know when I can test this so closing right now.