Describe the bug
Having updated Swashbuckle.AspNetCore to 2.0.0-preview.11 and ASP.NET Core 10 preview 3 in domaindrivendev/Swashbuckle.AspNetCore#3283, I've identified an issue where only one tag is returned when a larger set of tag referencess is assigned to an OpenAPI operation.
In creating a self-contained repro for the issue, I find that this is also an issue in 2.0.0-preview.16.
My guess is that there's an issue with how the custom OpenApiTagComparer class is implemented, which is used when assigning a value to the property here:
| publicHashSet<OpenApiTagReference>?Tags |
| { |
| get |
| { |
| return_tags; |
| } |
| set |
| { |
| if(valueisnull) |
| { |
| return; |
| } |
| _tags=valueisHashSet<OpenApiTagReference>tags&&tags.ComparerisOpenApiTagComparer? |
| tags: |
| newHashSet<OpenApiTagReference>(value,OpenApiTagComparer.Instance); |
| } |
| } |
Specifically, it looks like it doesn't cater for an OpenApiReference where Name resolves to null:
| publicboolEquals(IOpenApiTag?x,IOpenApiTag?y) |
| { |
| if(xisnull&&yisnull) |
| { |
| returntrue; |
| } |
| if(xisnull||yisnull) |
| { |
| returnfalse; |
| } |
| if(ReferenceEquals(x,y)) |
| { |
| returntrue; |
| } |
| returnStringComparer.Equals(x.Name,y.Name); |
| } |
Code To Reproduce
usingMicrosoft.OpenApi.Models;usingMicrosoft.OpenApi.Models.References;vardocument=newOpenApiDocument();vartags=newHashSet<OpenApiTagReference>();tags.Add(newOpenApiTagReference("one",document));tags.Add(newOpenApiTagReference("two",document));tags.Add(newOpenApiTagReference("three",document));Console.WriteLine("There are {0} original tags.",tags.Count);Console.WriteLine("The original tags are: {0}",string.Join(", ",tags.Select(t =>t.Reference.Id)));varoperation=newOpenApiOperation(){Tags=tags};Console.WriteLine("There are {0} tags in the operation.",operation.Tags.Count);Console.WriteLine("The operation tags are: {0}",string.Join(", ",operation.Tags.Select(t =>t.Reference.Id)));<ProjectSdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReferenceInclude="Microsoft.OpenApi"Version="2.0.0-preview.16" />
</ItemGroup>
</Project>
Expected behavior
There are 3 original tags.
The original tags are: one, two, three
There are 3 tags in the operation.
The operation tags are: one, two, three
Actual behaviour
There are 3 original tags.
The original tags are: one, two, three
There are 1 tags in the operation.
The operation tags are: one
Describe the bug
Having updated Swashbuckle.AspNetCore to 2.0.0-preview.11 and ASP.NET Core 10 preview 3 in domaindrivendev/Swashbuckle.AspNetCore#3283, I've identified an issue where only one tag is returned when a larger set of tag referencess is assigned to an OpenAPI operation.
In creating a self-contained repro for the issue, I find that this is also an issue in 2.0.0-preview.16.
My guess is that there's an issue with how the custom
OpenApiTagComparerclass is implemented, which is used when assigning a value to the property here:OpenAPI.NET/src/Microsoft.OpenApi/Models/OpenApiOperation.cs
Lines 29 to 45 in 63a8a34
Specifically, it looks like it doesn't cater for an
OpenApiReferencewhereNameresolves tonull:OpenAPI.NET/src/Microsoft.OpenApi/OpenApiTagComparer.cs
Lines 20 to 35 in 63a8a34
Code To Reproduce
Expected behavior
Actual behaviour