【问题标题】:Swashbuckle: Make non-nullable properties required in array typeSwashbuckle:在数组类型中设置不可为空的属性
【发布时间】:2019-08-26 14:23:18
【问题描述】:

我正在使用 autoRest 从一个 swagger 架构生成一个新客户端。我在模型中有 DateTime 列表

public class DateRange
{
   public IList<DateTime> Dates{ get; set; }
}

这是从该属性生成的 Json swagger 架构

  { ...
    "Dates": {
              "type": "array",
              "items": {
                "format": "date-time",
                "type": "string"
              }
            }
    ...
    }

这是我运行 autoRest 后得到的结果

public class DateRange
{

     [JsonProperty(PropertyName = "Dates")]
     public IList<System.DateTime?> Dates{ get; set; }
}

我想获得一个类似这样的不可为空的 dateTime 属性

public IList<System.DateTime> Dates{ get; set; }

【问题讨论】:

  • 这闻起来像 autorest 中的错误,您应该在那里报告。

标签: c# asp.net-web-api swagger-2.0 swashbuckle autorest


【解决方案1】:

更新您的 Swagger 架构,使您的属性如下所示:

dates:
    type: "array"
    items:
        format: "date-time"
        type: "string"
        x-nullable: false

然后在命令行中使用AutoRest生成客户端:

autorest --input-file="swagger.json" --output-folder="output" --csharp

导致:

/// <summary>
/// </summary>
[JsonProperty(PropertyName = "dates")]
public IList<System.DateTime> Dates { get; set; }

【讨论】:

  • 如果这解决了您的问题,请接受我的回答。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-16
  • 2014-02-04
相关资源
最近更新 更多