c# - 如何在 NSwagStudio 中为 C# 客户端自定义生成的 DTO

标签 c# nswag nswagstudio

我有一个用于 .NET 的 HttpClient 的通用包装器,但我想使用 NSwagStudio 的代码生成器生成调用我的通用客户端而不是标准 HttpClient 的代码。我已经实现了其中的大部分,但是有一部分我无法自定义:DTO 对象的代码。我知道它是从此处的 File.liquid 模板生成的:

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

我看不到如何修改从 Classes

生成的代码

生成的代码是:

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; }
}

我想使用 System.Text.Json 而不是 Newtonsoft,所以我要么想完全删除 Newtonsoft 属性,要么改用 JsonPropertyName

谁能指出我在哪里进行更改?

最佳答案

NSwagStudio has a option for Json

NSwagStudio 有一个 Json 选项

关于c# - 如何在 NSwagStudio 中为 C# 客户端自定义生成的 DTO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65131576/

相关文章:

c# - 处理遗留数据库时在 NHibernate 中建模多对一关系的最佳方法?

c# - Azure Blob 存储列表容器和 Blob

c# - 如何在从 asp.net c# 中的另一个下拉列表中选择项目后将项目加载到下拉列表中

c# - 是否可以在不使用 [JsonIgnore] 的情况下忽略 nswag 中的模型属性?

c# - 如何在 ASP.Net 图表控件中标记每周图表

c# - 从主体生成泛型参数的 swagger 模型

swagger - 在 ASP.NET Core 2.2 中使用 nswag 设置承载 token

c# - 使用 Swashbuckle 5.x 在通用 T 参数引用属性上指定 nullable = true

c# - NSwag MSBuild "The method ' get' on path '/api/Account' 已注册多次”