【问题标题】:Change NSwagStudio serialization setting to allow for Nulls更改 NSwagStudio 序列化设置以允许 Nulls
【发布时间】:2019-09-22 00:59:13
【问题描述】:

有没有办法更改 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


    【解决方案1】:

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

    API 规范示例:

        ReturnCode:
          type: integer
          nullable: true
    

    【讨论】:

    • 而如何在源代码中指定?
    • 源码规范写在上面问题Newtonsoft.Json.Required.AllowNull
    猜你喜欢
    • 2011-04-22
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    相关资源
    最近更新 更多