Skip to content

Commit 6526d29

Browse files
baywetCopilot
andcommitted
chore(reader): remove CreateAny helper
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 7cebb68 commit 6526d29

24 files changed

Lines changed: 43 additions & 52 deletions

src/Microsoft.OpenApi/Reader/JsonNodeHelper.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static List<JsonNode> CreateListOfAny(this JsonNode? node, ParsingContext
4242
throw new OpenApiReaderException("Cannot create a list from this type of node.", context);
4343
}
4444

45-
return jsonArray.OfType<JsonNode>().Select(static n => n.CreateAny()).Where(static i => i != null).ToList();
45+
return jsonArray.OfType<JsonNode>().ToList();
4646
}
4747

4848
public static List<T> CreateSimpleList<T>(this JsonNode? node, Func<JsonNode, OpenApiDocument?, T> map, OpenApiDocument? openApiDocument, ParsingContext context)
@@ -155,11 +155,6 @@ public static Dictionary<string, HashSet<T>> CreateArrayMap<T>(this JsonNode? no
155155
return nodes.ToDictionary(kvp => kvp.key, kvp => kvp.values);
156156
}
157157

158-
public static JsonNode CreateAny(this JsonNode? node)
159-
{
160-
return node ?? JsonNullSentinel.JsonNull;
161-
}
162-
163158
public static string? GetScalarValue(this JsonNode? node)
164159
{
165160
var scalarNode = node is JsonValue value ? value : throw new OpenApiException("Expected scalar value.");

src/Microsoft.OpenApi/Reader/V2/OpenApiHeaderDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internal static partial class OpenApiV2Deserializer
5252
},
5353
{
5454
"default",
55-
(o, n, _, c) => GetOrCreateSchema(o).Default = n.CreateAny()
55+
(o, n, _, c) => GetOrCreateSchema(o).Default = n
5656
},
5757
{
5858
"maximum",

src/Microsoft.OpenApi/Reader/V2/OpenApiParameterDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ internal static partial class OpenApiV2Deserializer
155155
},
156156
{
157157
"default",
158-
(o, n, t, c) => GetOrCreateSchema(o).Default = n.CreateAny()
158+
(o, n, t, c) => GetOrCreateSchema(o).Default = n
159159
},
160160
{
161161
"pattern",

src/Microsoft.OpenApi/Reader/V2/OpenApiResponseDeserializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static Dictionary<string, IOpenApiExample> LoadExamplesExtension(JsonNod
129129
example.Description = JsonNode.Value.GetScalarValue();
130130
break;
131131
case "value":
132-
example.Value = JsonNode.Value.CreateAny();
132+
example.Value = JsonNode.Value ?? JsonNullSentinel.JsonNull;
133133
break;
134134
case "externalValue":
135135
example.ExternalValue = JsonNode.Value.GetScalarValue();
@@ -155,7 +155,7 @@ private static void LoadExamples(OpenApiResponse response, JsonNode node, OpenAp
155155

156156
private static void LoadExample(OpenApiResponse response, string mediaType, JsonNode? node, ParsingContext context)
157157
{
158-
var exampleNode = node.CreateAny();
158+
var exampleNode = node ?? JsonNullSentinel.JsonNull;
159159

160160
response.Content ??= new Dictionary<string, IOpenApiMediaType>();
161161

src/Microsoft.OpenApi/Reader/V2/OpenApiSchemaDeserializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ internal static partial class OpenApiV2Deserializer
208208
},
209209
{
210210
"default",
211-
(o, n, _, c) => o.Default = n.CreateAny()
211+
(o, n, _, c) => o.Default = n
212212
},
213213
{
214214
"discriminator", (o, n, _, c) =>
@@ -240,7 +240,7 @@ internal static partial class OpenApiV2Deserializer
240240
},
241241
{
242242
"example",
243-
(o, n, _, c) => o.Example = n.CreateAny()
243+
(o, n, _, c) => o.Example = n
244244
},
245245
{
246246
OpenApiConstants.PatternPropertiesExtension,

src/Microsoft.OpenApi/Reader/V2/OpenApiV2Deserializer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static void ProcessAnyFields<T>(
6060

6161
public static JsonNode LoadAny(JsonNode node, OpenApiDocument hostDocument, ParsingContext context)
6262
{
63-
return node.CreateAny();
63+
return node;
6464
}
6565

6666
private static IOpenApiExtension LoadExtension(string name, JsonNode node, ParsingContext context)
@@ -69,7 +69,7 @@ private static IOpenApiExtension LoadExtension(string name, JsonNode node, Parsi
6969
{
7070
try
7171
{
72-
return parser(node.CreateAny(), OpenApiSpecVersion.OpenApi2_0);
72+
return parser(node, OpenApiSpecVersion.OpenApi2_0);
7373
}
7474
catch (OpenApiException ex)
7575
{
@@ -78,7 +78,7 @@ private static IOpenApiExtension LoadExtension(string name, JsonNode node, Parsi
7878
}
7979
}
8080

81-
return new JsonNodeExtension(node.CreateAny());
81+
return new JsonNodeExtension(node);
8282
}
8383

8484
private static string? LoadString(JsonNode node)

src/Microsoft.OpenApi/Reader/V3/OpenApiExampleDeserializer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal static partial class OpenApiV3Deserializer
2525
},
2626
{
2727
"value",
28-
(o, n, _, c) => o.Value = n.CreateAny()
28+
(o, n, _, c) => o.Value = n
2929
},
3030
{
3131
"externalValue",
@@ -36,7 +36,7 @@ internal static partial class OpenApiV3Deserializer
3636
private static readonly PatternFieldMap<OpenApiExample> _examplePatternFields =
3737
new()
3838
{
39-
{s => s.Equals("x-oai-dataValue", StringComparison.OrdinalIgnoreCase), (o, p, n, _, c) => o.DataValue = n.CreateAny()},
39+
{s => s.Equals("x-oai-dataValue", StringComparison.OrdinalIgnoreCase), (o, p, n, _, c) => o.DataValue = n},
4040
{s => s.Equals("x-oai-serializedValue", StringComparison.OrdinalIgnoreCase), (o, p, n, _, c) => o.SerializedValue = n.GetScalarValue()},
4141
{s => s.StartsWith(OpenApiConstants.ExtensionFieldNamePrefix, StringComparison.OrdinalIgnoreCase), (o, p, n, _, c) => o.AddExtension(p, LoadExtension(p, n, c))}
4242
};

src/Microsoft.OpenApi/Reader/V3/OpenApiHeaderDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ internal static partial class OpenApiV3Deserializer
101101
},
102102
{
103103
"example",
104-
(o, n, _, c) => o.Example = n.CreateAny()
104+
(o, n, _, c) => o.Example = n
105105
},
106106
};
107107

src/Microsoft.OpenApi/Reader/V3/OpenApiMediaTypeDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal static partial class OpenApiV3Deserializer
2626
},
2727
{
2828
OpenApiConstants.Example,
29-
(o, n, _, c) => o.Example = n.CreateAny()
29+
(o, n, _, c) => o.Example = n
3030
},
3131
{
3232
OpenApiConstants.Encoding,

src/Microsoft.OpenApi/Reader/V3/OpenApiParameterDeserializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ internal static partial class OpenApiV3Deserializer
114114
},
115115
{
116116
"example",
117-
(o, n, _, c) => o.Example = n.CreateAny()
117+
(o, n, _, c) => o.Example = n
118118
},
119119
};
120120

0 commit comments

Comments
 (0)