简体   繁体   中英

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.

datamember example:

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

swashbuckle swagger-ui model output:

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 ).

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. "shipDate" there is defined as (string, optional) just like your StartDate field.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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