首页 > 解决方案 > 更改 NSwagStudio 序列化设置以允许 Nulls

问题描述

有没有办法更改 NSwagStudio 中的设置,以便当 JSON 序列化设置输出为Newtonsoft.Json.Required.AllowNull而不是Newtonsoft.Json.Required.Always

我目前手动更改了属性以允许空值。

[Newtonsoft.Json.JsonProperty("returnCode", Required = Newtonsoft.Json.Required.Always)]
public int ReturnCode { get; set; }

我需要它是:

[Newtonsoft.Json.JsonProperty("returnCode", Required = Newtonsoft.Json.Required.AllowNull)]
public int ReturnCode { get; set; }

标签: nswagstudio

解决方案


如果它在 API 规范中不可为空,则它在生成的代码中也不能为空

API 规范示例:

    ReturnCode:
      type: integer
      nullable: true

推荐阅读