Skip to content

Commit 23395c5

Browse files
committed
fix: add logic for serializing date time objects
1 parent 9ed37d2 commit 23395c5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/Microsoft.OpenApi/Writers/OpenApiWriterAnyExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using System;
45
using System.Collections.Generic;
6+
using System.Globalization;
57
using System.Text.Json;
68
using System.Text.Json.Nodes;
79
using Microsoft.OpenApi.Any;
@@ -111,6 +113,10 @@ private static void WritePrimitive(this IOpenApiWriter writer, JsonValue jsonVal
111113
{
112114
if (jsonValue.TryGetValue(out string stringValue))
113115
writer.WriteValue(stringValue);
116+
else if (jsonValue.TryGetValue(out DateTime dateTimeValue))
117+
writer.WriteValue(dateTimeValue.ToString("o", CultureInfo.InvariantCulture)); // ISO 8601 format
118+
else if (jsonValue.TryGetValue(out DateTimeOffset dateTimeOffsetValue))
119+
writer.WriteValue(dateTimeOffsetValue.ToString("o", CultureInfo.InvariantCulture));
114120
else if (jsonValue.TryGetValue(out bool boolValue))
115121
writer.WriteValue(boolValue);
116122
// write number values

0 commit comments

Comments
 (0)