@@ -2,6 +2,17 @@ namespace Atc.Rest.ApiGenerator.OpenApi.Extensions;
22
33public static class OpenApiAnyExtensions
44{
5+ /// <summary>
6+ /// Returns a string representation of common OpenAPI primitives with predictable, culture-fixed formatting.
7+ /// Notes:
8+ /// - Booleans -> "true"/"false" (lowercase JSON style).
9+ /// - Date -> "yyyy-MM-dd" (e.g., 2025-09-03), culture-fixed to avoid month/day swaps.
10+ /// - DateTime -> ISO 8601 round-trip "O" (e.g., 2025-09-03T12:34:56.7890123+00:00).
11+ /// - Double/Float -> "N" using en-US (group separators + decimals; e.g., 1,234.00).
12+ /// - Long/Integer -> default numeric ("G") with en-US (no group separators, no decimals; e.g., 1234).
13+ /// - Null -> "null" literal.
14+ /// - String/Password -> empty -> "string.Empty"; otherwise the raw value (unquoted).
15+ /// </summary>
516 public static string ? GetDefaultValueAsString (
617 this IOpenApiAny ? openApiAny )
718 {
@@ -12,12 +23,17 @@ public static class OpenApiAnyExtensions
1223
1324 return openApiAny switch
1425 {
15- OpenApiDouble apiDouble => apiDouble . Value . ToString ( "N" ) ,
16- OpenApiFloat apiFloat => apiFloat . Value . ToString ( "N" ) ,
17- OpenApiInteger apiInteger => apiInteger . Value . ToString ( ) ,
18- OpenApiString apiString => string . IsNullOrEmpty ( apiString . Value ) ? "string.Empty" : $ "{ apiString . Value } ",
1926 OpenApiBoolean { Value : true } => "true" ,
2027 OpenApiBoolean { Value : false } => "false" ,
28+ OpenApiDate apiDate => apiDate . Value . ToString ( "yyyy-MM-dd" , GlobalizationConstants . EnglishCultureInfo ) ,
29+ OpenApiDateTime apiDateTime => apiDateTime . Value . ToString ( "O" , GlobalizationConstants . EnglishCultureInfo ) ,
30+ OpenApiDouble apiDouble => apiDouble . Value . ToString ( "N" , GlobalizationConstants . EnglishCultureInfo ) ,
31+ OpenApiFloat apiFloat => apiFloat . Value . ToString ( "N" , GlobalizationConstants . EnglishCultureInfo ) ,
32+ OpenApiLong apiLong => apiLong . Value . ToString ( GlobalizationConstants . EnglishCultureInfo ) ,
33+ OpenApiInteger apiInteger => apiInteger . Value . ToString ( GlobalizationConstants . EnglishCultureInfo ) ,
34+ OpenApiNull => "null" ,
35+ OpenApiPassword apiPassword => string . IsNullOrEmpty ( apiPassword . Value ) ? "string.Empty" : $ "{ apiPassword . Value } ",
36+ OpenApiString apiString => string . IsNullOrEmpty ( apiString . Value ) ? "string.Empty" : $ "{ apiString . Value } ",
2137 _ => throw new NotImplementedException ( "Property initializer: " + openApiAny . GetType ( ) ) ,
2238 } ;
2339 }
0 commit comments