@@ -52,15 +52,15 @@ public static void ValidateDataTypeMismatch(
52
52
}
53
53
54
54
// convert value to JsonElement and access the ValueKind property to determine the type.
55
- var jsonElement = JsonDocument . Parse ( JsonSerializer . Serialize ( value ) ) . RootElement ;
55
+ var valueKind = value . GetValueKind ( ) ;
56
56
57
57
var type = schema . Type . ToIdentifier ( ) ;
58
58
var format = schema . Format ;
59
59
var nullable = schema . Nullable ;
60
60
61
61
// Before checking the type, check first if the schema allows null.
62
62
// If so and the data given is also null, this is allowed for any type.
63
- if ( nullable && jsonElement . ValueKind is JsonValueKind . Null )
63
+ if ( nullable && valueKind is JsonValueKind . Null )
64
64
{
65
65
return ;
66
66
}
@@ -70,7 +70,7 @@ public static void ValidateDataTypeMismatch(
70
70
// It is not against the spec to have a string representing an object value.
71
71
// To represent examples of media types that cannot naturally be represented in JSON or YAML,
72
72
// a string value can contain the example with escaping where necessary
73
- if ( jsonElement . ValueKind is JsonValueKind . String )
73
+ if ( valueKind is JsonValueKind . String )
74
74
{
75
75
return ;
76
76
}
@@ -110,7 +110,7 @@ public static void ValidateDataTypeMismatch(
110
110
// It is not against the spec to have a string representing an array value.
111
111
// To represent examples of media types that cannot naturally be represented in JSON or YAML,
112
112
// a string value can contain the example with escaping where necessary
113
- if ( jsonElement . ValueKind is JsonValueKind . String )
113
+ if ( valueKind is JsonValueKind . String )
114
114
{
115
115
return ;
116
116
}
@@ -138,7 +138,7 @@ public static void ValidateDataTypeMismatch(
138
138
139
139
if ( type is "integer" or "number" && format is "int32" )
140
140
{
141
- if ( jsonElement . ValueKind is not JsonValueKind . Number )
141
+ if ( valueKind is not JsonValueKind . Number )
142
142
{
143
143
context . CreateWarning (
144
144
ruleName ,
@@ -150,7 +150,7 @@ public static void ValidateDataTypeMismatch(
150
150
151
151
if ( type is "integer" or "number" && format is "int64" )
152
152
{
153
- if ( jsonElement . ValueKind is not JsonValueKind . Number )
153
+ if ( valueKind is not JsonValueKind . Number )
154
154
{
155
155
context . CreateWarning (
156
156
ruleName ,
@@ -162,7 +162,7 @@ public static void ValidateDataTypeMismatch(
162
162
163
163
if ( type is "integer" )
164
164
{
165
- if ( jsonElement . ValueKind is not JsonValueKind . Number )
165
+ if ( valueKind is not JsonValueKind . Number )
166
166
{
167
167
context . CreateWarning (
168
168
ruleName ,
@@ -174,7 +174,7 @@ public static void ValidateDataTypeMismatch(
174
174
175
175
if ( type is "number" && format is "float" )
176
176
{
177
- if ( jsonElement . ValueKind is not JsonValueKind . Number )
177
+ if ( valueKind is not JsonValueKind . Number )
178
178
{
179
179
context . CreateWarning (
180
180
ruleName ,
@@ -186,7 +186,7 @@ public static void ValidateDataTypeMismatch(
186
186
187
187
if ( type is "number" && format is "double" )
188
188
{
189
- if ( jsonElement . ValueKind is not JsonValueKind . Number )
189
+ if ( valueKind is not JsonValueKind . Number )
190
190
{
191
191
context . CreateWarning (
192
192
ruleName ,
@@ -198,7 +198,7 @@ public static void ValidateDataTypeMismatch(
198
198
199
199
if ( type is "number" )
200
200
{
201
- if ( jsonElement . ValueKind is not JsonValueKind . Number )
201
+ if ( valueKind is not JsonValueKind . Number )
202
202
{
203
203
context . CreateWarning (
204
204
ruleName ,
@@ -210,7 +210,7 @@ public static void ValidateDataTypeMismatch(
210
210
211
211
if ( type is "string" && format is "byte" )
212
212
{
213
- if ( jsonElement . ValueKind is not JsonValueKind . String )
213
+ if ( valueKind is not JsonValueKind . String )
214
214
{
215
215
context . CreateWarning (
216
216
ruleName ,
@@ -222,7 +222,7 @@ public static void ValidateDataTypeMismatch(
222
222
223
223
if ( type is "string" && format is "date" )
224
224
{
225
- if ( jsonElement . ValueKind is not JsonValueKind . String )
225
+ if ( valueKind is not JsonValueKind . String )
226
226
{
227
227
context . CreateWarning (
228
228
ruleName ,
@@ -234,7 +234,7 @@ public static void ValidateDataTypeMismatch(
234
234
235
235
if ( type is "string" && format is "date-time" )
236
236
{
237
- if ( jsonElement . ValueKind is not JsonValueKind . String )
237
+ if ( valueKind is not JsonValueKind . String )
238
238
{
239
239
context . CreateWarning (
240
240
ruleName ,
@@ -246,7 +246,7 @@ public static void ValidateDataTypeMismatch(
246
246
247
247
if ( type is "string" && format is "password" )
248
248
{
249
- if ( jsonElement . ValueKind is not JsonValueKind . String )
249
+ if ( valueKind is not JsonValueKind . String )
250
250
{
251
251
context . CreateWarning (
252
252
ruleName ,
@@ -258,7 +258,7 @@ public static void ValidateDataTypeMismatch(
258
258
259
259
if ( type is "string" )
260
260
{
261
- if ( jsonElement . ValueKind is not JsonValueKind . String )
261
+ if ( valueKind is not JsonValueKind . String )
262
262
{
263
263
context . CreateWarning (
264
264
ruleName ,
@@ -270,7 +270,7 @@ public static void ValidateDataTypeMismatch(
270
270
271
271
if ( type is "boolean" )
272
272
{
273
- if ( jsonElement . ValueKind is not JsonValueKind . True && jsonElement . ValueKind is not JsonValueKind . False )
273
+ if ( valueKind is not JsonValueKind . True && valueKind is not JsonValueKind . False )
274
274
{
275
275
context . CreateWarning (
276
276
ruleName ,
0 commit comments