Search code examples
c#nswagnswagstudio

How do I customise the generated DTO for the C# Client in NSwagStudio


I have a generic wrapper for .NET's HttpClient but I'd like to use NSwagStudio's code generator to generate code that calls my generic client rather than the standard HttpClient. I have achieved most of this however there's one part I'm not able to customise: the code for the DTO objects. I know that it's being generated from the File.liquid template here:

{% if GenerateContracts -%}
    {{ Classes | tab }}

I can't see how to modify the code that is generated from Classes

The code that gets generated is:

public partial class ExampleDomainObject 
{
    [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
    public int Id { get; set; }

    [Newtonsoft.Json.JsonProperty("name", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)]
    public string Name { get; set; }
}

I want to use System.Text.Json instead of Newtonsoft so I either want to remove the Newtonsoft attribute completely or use JsonPropertyName instead.

Can anyone point me to where to make the change?


Solution

  • NSwagStudio has a option for Json

    NSwagStudio has a option for Json