You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"The solution for now is to use System.Text.Json for serialization and add NSwag with a Newtonsoft.Json contract resolver which resembles the System.Text.Json serializer behavior..."
Sorry, Im pretty new to this
Im using .NET 6
I have a reference to Microsoft.AspNetCore.Mvc.NewtonsoftJson added to the project
I have the following in my startup.cs
I'm using STJ for serialization
In AddOpenApiDocument(), SerializerSettings is always null.
I know I'm supposed to use SystemTextJsonUtilities. ConvertJsonOptionsToNewtonsoftSettings() somewhere, but I dont have access to my STJ settings in AddOpenApiDocument().
I'm probably doing something silly here. But any code snippets would be appreciated.
Thanks for your help.
The text was updated successfully, but these errors were encountered:
You do not need to change the SerializerSettings in AddOpenApiDocument as it will automatically use the configuration from the AddJsonOptions... or what are you trying to solve here?
At first, I was trying to figure out why the camel case Json naming policy for enums was not working. Then I found the issue I linked above and went into a rabbit hole. But the actual fix was I had to upgrade NSwag from 13.15.7 to 13.15.10. That seems to work great!
Now I'm trying to see if there is a way to specify custom names for enums that will be used for swagger and serialization.
For example, for the following enum
publicenumTestEnum{/// <summary>/// This is the thing of one/// </summary>[EnumMember(Value="Another-One")]OneThing,/// <summary>/// Another thing of two/// </summary>[EnumMember(Value="Trick-Or-Treat")]TwoThing}
I want swagger and the STJ (serialize and deserialize) to use the string in the EnumMember attribute, not the actual name of the enum. Somehow NSwag is respecting EnumMemberAttribute, but STJ does not.
But then I found this issue flagging my problem (while writing this response).
Hi there
Im trying to implement the solution posts by @RicoSuter here
#1014 (comment)
"The solution for now is to use System.Text.Json for serialization and add NSwag with a Newtonsoft.Json contract resolver which resembles the System.Text.Json serializer behavior..."
Sorry, Im pretty new to this
Im using .NET 6
I have a reference to
Microsoft.AspNetCore.Mvc.NewtonsoftJson
added to the projectI have the following in my startup.cs
I'm using STJ for serialization
In AddOpenApiDocument(), SerializerSettings is always
null
.I know I'm supposed to use
SystemTextJsonUtilities. ConvertJsonOptionsToNewtonsoftSettings()
somewhere, but I dont have access to my STJ settings inAddOpenApiDocument()
.I'm probably doing something silly here. But any code snippets would be appreciated.
Thanks for your help.
The text was updated successfully, but these errors were encountered: