I'm using client's Swagger YAML file to generate models for one API where one property is a string type(ISO 8601) in swagger filevalidUntil: type: string
and c# props is public string ValidUntil { get; set; }
which were binding string data properly"validUntil": "2022-07-12T07:03:45.428Z"
as string, but since the API migrated to .net core
string value is being identified as DateTime
and property is null.
Here is Swagger.yaml extract
BaseClass:
type: object
title: BaseClass
properties:
id:
type: string
reference:
type: string
validUntil:
type: string
required:
- id
- validUntil
And this validUntil
props in c#
[Newtonsoft.Json.JsonProperty("validUntil", Required = Newtonsoft.Json.Required.Always)]
[System.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
public string ValidUntil { get; set; }
I'm using NSwag to generate models.
..\..\packages\NSwag.MSBuild.11.20.1\tools\Win\NSwag.exe swagger2csclient /input:swagger.yaml /output:ApiModels.cs /GenerateClientClasses:false /namespace:Api.Model /GenerateDtoTypes:true /ClassStyle:Poco /GenerateJsonMethods:false /ArrayType:System.Collections.Generic.List /ArrayBaseType:System.Collections.Generic.List /GenerateExceptionClasses:false
I just want to understand the reasons behind this. It is something related to Newtonsoft json library?