@@ -56,13 +56,61 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
56
56
}
57
57
58
58
var value = ( ( OpenApiString ) openApiAny ) . Value ;
59
+ var type = schema ? . Type ;
60
+ var format = schema ? . Format ;
59
61
60
- // For explicit strings only try to guess if it's a DateTimeOffset
61
62
if ( ( ( OpenApiString ) openApiAny ) . IsExplicit ( ) )
62
63
{
63
- if ( DateTimeOffset . TryParse ( value , CultureInfo . InvariantCulture , DateTimeStyles . None , out var dateTimeValue ) )
64
+ // More narrow type detection for explicit strings, only check types that are passed as strings
65
+ if ( schema == null )
64
66
{
65
- return new OpenApiDateTime ( dateTimeValue ) ;
67
+ if ( DateTimeOffset . TryParse ( value , CultureInfo . InvariantCulture , DateTimeStyles . None , out var dateTimeValue ) )
68
+ {
69
+ return new OpenApiDateTime ( dateTimeValue ) ;
70
+ }
71
+ }
72
+ else if ( type == "string" )
73
+ {
74
+ if ( format == "byte" )
75
+ {
76
+ try
77
+ {
78
+ return new OpenApiByte ( Convert . FromBase64String ( value ) ) ;
79
+ }
80
+ catch ( FormatException )
81
+ { }
82
+ }
83
+
84
+ if ( format == "binary" )
85
+ {
86
+ try
87
+ {
88
+ return new OpenApiBinary ( Encoding . UTF8 . GetBytes ( value ) ) ;
89
+ }
90
+ catch ( EncoderFallbackException )
91
+ { }
92
+ }
93
+
94
+ if ( format == "date" )
95
+ {
96
+ if ( DateTimeOffset . TryParse ( value , CultureInfo . InvariantCulture , DateTimeStyles . None , out var dateValue ) )
97
+ {
98
+ return new OpenApiDate ( dateValue . Date ) ;
99
+ }
100
+ }
101
+
102
+ if ( format == "date-time" )
103
+ {
104
+ if ( DateTimeOffset . TryParse ( value , CultureInfo . InvariantCulture , DateTimeStyles . None , out var dateTimeValue ) )
105
+ {
106
+ return new OpenApiDateTime ( dateTimeValue ) ;
107
+ }
108
+ }
109
+
110
+ if ( format == "password" )
111
+ {
112
+ return new OpenApiPassword ( value ) ;
113
+ }
66
114
}
67
115
68
116
return openApiAny ;
@@ -107,9 +155,6 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
107
155
}
108
156
else
109
157
{
110
- var type = schema . Type ;
111
- var format = schema . Format ;
112
-
113
158
if ( type == "integer" && format == "int32" )
114
159
{
115
160
if ( int . TryParse ( value , NumberStyles . Integer , CultureInfo . InvariantCulture , out var intValue ) )
@@ -202,7 +247,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
202
247
203
248
if ( type == "string" )
204
249
{
205
- return new OpenApiString ( value ) ;
250
+ return openApiAny ;
206
251
}
207
252
208
253
if ( type == "boolean" )
0 commit comments