Skip to content

fix: support reinitializing OpenApiOperation.Tags to null and custom comparers - #3116

Open
Austin (AustinAviv) wants to merge 2 commits into
microsoft:mainfrom
AustinAviv:fix/operation-tags-null-and-custom-comparer
Open

Austin (AustinAviv) wants to merge 2 commits into
microsoft:mainfrom
AustinAviv:fix/operation-tags-null-and-custom-comparer

Conversation

@AustinAviv

Copy link
Copy Markdown

Description

Aligns OpenApiOperation.Tags setter and copy constructor with OpenApiDocument.Tags so that assigning
ull resets the tags property, and custom equality comparers or sorted sets are retained instead of being forced into OpenApiTagComparer.Instance.

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 assign _tags = null; when incoming value is null.
  • Added pattern match in OpenApiOperation.Tags setter to preserve custom comparers, SortedSet, and ImmutableSortedSet (matching OpenApiDocument.Tags).
  • Updated OpenApiOperation(OpenApiOperation operation) copy constructor to preserve custom comparers and sorted sets.
  • Added unit tests covering reinitializing tags to null, preserving custom tag comparers, and sorted set handling.

Testing

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

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.

…comparers

Align OpenApiOperation.Tags setter and copy constructor with OpenApiDocument.Tags to avoid silently ignoring null assignments and to preserve custom equality comparers or sorted sets.

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.

🟡 Changes recommended

Immutable-set behavior lacks coverage, and the sorted-set test does not verify comparer preservation.

2 open findings
What changed in this PR

Fixes operation tag resetting and preserves custom set semantics.

Changes:

  • Allows resetting OpenApiOperation.Tags to null.
  • Preserves custom comparers, sorted sets, and immutable sorted sets.
  • Adds regression tests for most updated behaviors.
File Description
src/​Microsoft.OpenApi/​Models/​OpenApiOperation.cs Updates tag assignment and copying behavior.
test/​Microsoft.OpenApi.Tests/​Models/​OpenApiOperationTests.cs Adds tag setter and copy-constructor tests.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

HashSet<OpenApiTagReference> tags when tags.Comparer != EqualityComparer<OpenApiTagReference>.Default => value,
SortedSet<OpenApiTagReference> => value,
#if NET
ImmutableSortedSet<OpenApiTagReference> => value,
Comment thread test/Microsoft.OpenApi.Tests/Models/OpenApiOperationTests.cs Outdated
new HashSet<OpenApiTagReference>(value, OpenApiTagComparer.Instance);
_tags = value switch
{
HashSet<OpenApiTagReference> tags when tags.Comparer != EqualityComparer<OpenApiTagReference>.Default => value,
Tags = operation.Tags != null ? new HashSet<OpenApiTagReference>(operation.Tags) : null;
Tags = operation.Tags switch
{
HashSet<OpenApiTagReference> tags when tags.Comparer != EqualityComparer<OpenApiTagReference>.Default => new HashSet<OpenApiTagReference>(tags, tags.Comparer),
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 13:29

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.

🔵 Needs a closer look

The new immutable sorted-set assignment and copy paths lack test coverage.

1 open finding
1 resolved since last review

🧠 Review effort: Balanced

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

3 participants