简体   繁体   English

通过 swashbuckle webapi 2 C# 在 swagger UI 上的 DataContract 模型中显示 dateTime 数据类型

[英]show dateTime dataType in DataContract model on swagger UI via swashbuckle webapi 2 C#

I am using a datacontract for the model and the datetime datamember is working properly, however swagger ui is showing the datatype as string instead of dateTime.我正在为模型使用数据合同,并且日期时间数据成员工作正常,但是 swagger ui 将数据类型显示为字符串而不是日期时间。

datamember example:数据成员示例:

[DataMember(EmitDefaultValue = false, Order = 6), XmlElement(Namespace = apiNameSpace, Order = 6)]
public DateTime? StartDate { get; set; } = null;

swashbuckle swagger-ui model output: swashbuckle swagger-ui 模型输出:

StartDate (string, optional):开始日期(字符串,可选):

This is per the Swagger 2.0 spec (see https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md ).这是根据 Swagger 2.0 规范(参见https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md )。

The spec says that a dateTime should be represented as a string type, with the associated "format" property set to "date-time".规范说日期时间应该表示为字符串类型,关联的“格式”属性设置为“日期时间”。

Have a look at http://petstore.swagger.io/#!/store/placeOrder if you want to see an example.如果您想查看示例,请查看http://petstore.swagger.io/#!/store/placeOrder "shipDate" there is defined as (string, optional) just like your StartDate field. “shipDate”定义为(字符串,可选),就像您的 StartDate 字段一样。

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

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