Skip to content

Commit ab5f73b

Browse files
committed
chore: adds kind validation to avoid unnecessary value read
Signed-off-by: Vincent Biret <[email protected]>
1 parent b448384 commit ab5f73b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/Microsoft.OpenApi.YamlReader/YamlConverter.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Globalization;
44
using System.Linq;
5+
using System.Text.Json;
56
using System.Text.Json.Nodes;
67
using SharpYaml;
78
using SharpYaml.Serialization;
@@ -135,7 +136,8 @@ private static YamlScalarNode ToYamlScalar(this JsonValue val)
135136
{
136137
// Try to get the underlying value based on its actual type
137138
// First try to get it as a string
138-
if (val.TryGetValue(out string? stringValue))
139+
if (val.GetValueKind() == JsonValueKind.String &&
140+
val.TryGetValue(out string? stringValue))
139141
{
140142
// For string values, we need to determine if they should be quoted in YAML
141143
// Strings that look like numbers, booleans, or null need to be quoted

0 commit comments

Comments
 (0)