繁体   English   中英

Swashbuckle:使数组类型需要非可空属性

[英]Swashbuckle: Make non-nullable properties required in array type

我正在使用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; }

更新您的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; }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM