Skip to content

fix: Support custom tag ordering and null assignment in OpenApiOperation.Tags - #3128

Open
Hardik K (hardikkaurani) wants to merge 1 commit into
microsoft:mainfrom
hardikkaurani:fix/operation-tags-custom-comparers-and-null
Open

Hardik K (hardikkaurani) wants to merge 1 commit into
microsoft:mainfrom
hardikkaurani:fix/operation-tags-custom-comparers-and-null

Conversation

@hardikkaurani

Copy link
Copy Markdown

Pull Request

Description

This PR brings OpenApiOperation.Tags behavior into parity with OpenApiDocument.Tags (which was updated in #3053 and #3054).

Currently, OpenApiOperation.Tags:

  1. Silently ignores assignments of null, preventing callers from resetting the tags property to null.
  2. Always wraps incoming sets in new HashSet<OpenApiTagReference>(value, OpenApiTagComparer.Instance) unless it was already a HashSet<OpenApiTagReference> using OpenApiTagComparer. This discards custom comparers, custom tag orderings (SortedSet<OpenApiTagReference>), and ImmutableSortedSet<OpenApiTagReference>.

This fix updates the setter to allow null and preserves custom comparers, SortedSet, and ImmutableSortedSet.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Related Issue(s)

Fixes #3115

Changes Made

  • Updated OpenApiOperation.Tags setter to reset _tags = null when assigned null.
  • Updated OpenApiOperation.Tags setter to preserve HashSet instances with non-default comparers, SortedSet<OpenApiTagReference>, and ImmutableSortedSet<OpenApiTagReference>, aligning with OpenApiDocument.Tags.
  • Added conditional import using System.Collections.Immutable; under #if NET.
  • Added unit tests in OpenApiOperationTests.cs verifying null re-initialization, custom equality comparers, sorted sets, and immutable sorted sets.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Local verification:

  • dotnet run --project test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj -> 1304 passed, 0 failed.
  • dotnet run --project test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj -> 635 passed, 0 failed.

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Versions applicability

  • My change applies to the version 1.X of the library, if so PR link:
  • My change applies to the version 2.X of the library, if so PR link:
  • My change applies to the version 3.X of the library, if so PR link:
  • I have evaluated the applicability of my change against the other versions above.

Additional Notes

cc Vincent Biret (@baywet) for review as this mirrors the previous improvements made to OpenApiDocument.Tags.

@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner October 19, 2026 19:01
Copilot AI balanced review requested due to automatic review settings October 19, 2026 19:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenApiOperation.Tags ignores null assignment and discards custom comparers

2 participants