Skip to content

Commit 3764142

Browse files
authored
fix: Don't silently skip null assignment to OpenApiDocument.Tags
Don't silently skip null assignment to OpenApiDocument.Tags
1 parent 2bad4da commit 3764142

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public ISet<OpenApiTag>? Tags
8989
{
9090
if (value is null)
9191
{
92+
_tags = null;
9293
return;
9394
}
9495
_tags = value switch

test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,17 @@ public void TagsSupportsCustomComparer()
21452145
Assert.Equal(2, document.Tags.Count);
21462146
}
21472147

2148+
[Fact]
2149+
public void TagsCanBeReInitializedToNull()
2150+
{
2151+
var document = new OpenApiDocument();
2152+
Assert.Null(document.Tags);
2153+
document.Tags = new HashSet<OpenApiTag>();
2154+
Assert.NotNull(document.Tags);
2155+
document.Tags = null;
2156+
Assert.Null(document.Tags);
2157+
}
2158+
21482159
private sealed class CaseInsensitiveOpenApiTagEqualityComparer : IEqualityComparer<OpenApiTag>
21492160
{
21502161
public bool Equals(OpenApiTag x, OpenApiTag y)

0 commit comments

Comments
 (0)