Skip to content

Commit 16161eb

Browse files
committed
fix: empty tag causes Exception generating Kiota client #2283
1 parent 9fecf94 commit 16161eb

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ internal static partial class OpenApiV2Deserializer
2222
/// <summary>
2323
/// Have a default empty tag we can use to filter out empty tags.
2424
/// </summary>
25-
private static OpenApiTagReference emptyTagReference = new("empty");
2625
private static readonly FixedFieldMap<OpenApiOperation> _operationFixedFields =
2726
new()
2827
{
@@ -33,12 +32,12 @@ internal static partial class OpenApiV2Deserializer
3332
{
3433
var val = valueNode.GetScalarValue();
3534
if (string.IsNullOrEmpty(val))
36-
return emptyTagReference; // Avoid exception on empty tag, we'll remove these from the list further on
35+
return null; // Avoid exception on empty tag, we'll remove these from the list further on
3736
return LoadTagByReference(val , doc);
3837
},
3938
doc)
4039
// Filter out empty tags instead of excepting on them
41-
.Where(n => !object.ReferenceEquals(emptyTagReference, n)).ToList() is {Count: > 0} tags)
40+
.OfType<OpenApiTagReference>().ToList() is {Count: > 0} tags)
4241
{
4342
o.Tags = new HashSet<OpenApiTagReference>(tags, OpenApiTagComparer.Instance);
4443
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ internal static partial class OpenApiV3Deserializer
2020
/// <summary>
2121
/// Have a default empty tag we can use to filter out empty tags.
2222
/// </summary>
23-
private static OpenApiTagReference emptyTagReference = new("empty");
2423
private static readonly FixedFieldMap<OpenApiOperation> _operationFixedFields =
2524
new()
2625
{
@@ -31,12 +30,12 @@ internal static partial class OpenApiV3Deserializer
3130
{
3231
var val = valueNode.GetScalarValue();
3332
if (string.IsNullOrEmpty(val))
34-
return emptyTagReference; // Avoid exception on empty tag, we'll remove these from the list further on
33+
return null; // Avoid exception on empty tag, we'll remove these from the list further on
3534
return LoadTagByReference(val , doc);
3635
},
3736
doc)
3837
// Filter out empty tags instead of excepting on them
39-
.Where(n => !object.ReferenceEquals(emptyTagReference, n)).ToList() is {Count: > 0} tags)
38+
.OfType<OpenApiTagReference>().ToList() is {Count: > 0} tags)
4039
{
4140
o.Tags = new HashSet<OpenApiTagReference>(tags, OpenApiTagComparer.Instance);
4241
}

src/Microsoft.OpenApi/Reader/V31/OpenApiOperationDeserializer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ internal static partial class OpenApiV31Deserializer
1717
/// <summary>
1818
/// Have a default empty tag we can use to filter out empty tags.
1919
/// </summary>
20-
private static OpenApiTagReference emptyTagReference = new("empty");
2120
private static readonly FixedFieldMap<OpenApiOperation> _operationFixedFields =
2221
new()
2322
{
@@ -28,12 +27,12 @@ internal static partial class OpenApiV31Deserializer
2827
{
2928
var val = valueNode.GetScalarValue();
3029
if (string.IsNullOrEmpty(val))
31-
return emptyTagReference; // Avoid exception on empty tag, we'll remove these from the list further on
30+
return null; // Avoid exception on empty tag, we'll remove these from the list further on
3231
return LoadTagByReference(val , doc);
3332
},
3433
doc)
3534
// Filter out empty tags instead of excepting on them
36-
.Where(n => !object.ReferenceEquals(emptyTagReference, n)).ToList() is {Count: > 0} tags)
35+
.OfType<OpenApiTagReference>().ToList() is {Count: > 0} tags)
3736
{
3837
o.Tags = new HashSet<OpenApiTagReference>(tags, OpenApiTagComparer.Instance);
3938
}

0 commit comments

Comments
 (0)