Skip to content

Commit 16e9c7a

Browse files
committed
Use the TimeOfDay property of a date value to determine whether its a date-only or date-time property
1 parent 4de9313 commit 16e9c7a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Microsoft.OpenApi.Readers/ParseNodes/OpenApiAnyConverter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
6363
{
6464
// More narrow type detection for explicit strings, only check types that are passed as strings
6565
if (schema == null)
66-
{
66+
{
6767
if (DateTimeOffset.TryParse(value, CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateTimeValue))
6868
{
69-
return new OpenApiDateTime(dateTimeValue);
69+
// if the time component is exactly midnight(00:00:00) meaning no time has elapsed, return a date-only value
70+
return dateTimeValue.TimeOfDay == TimeSpan.Zero ? new OpenApiDate(dateTimeValue.Date)
71+
: new OpenApiDateTime(dateTimeValue);
7072
}
7173
}
7274
else if (type == "string")

0 commit comments

Comments
 (0)