Skip to content

fix: honor OpenAPI transformer registration order - #67925

Open
baywet wants to merge 2 commits into
dotnet:mainfrom
baywet:fix/ordering-transformers
Open

baywet wants to merge 2 commits into
dotnet:mainfrom
baywet:fix/ordering-transformers

Conversation

@baywet

@baywet baywet commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the OpenAPI transformer ordering issue discussed in https://github.com/dotnet/aspnetcore/issues/65723#issuecomment-5025789850.\n\nThis keeps the existing per-transformer-type lists while tracking registrations in a unified internal list so document transformers registered before operation/schema transformers can run before operation generation. This allows document transformers to pre-populate document-level tag metadata without operation tag discovery replacing it.\n\nValidation:\n- Docker: dotnet test src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Microsoft.AspNetCore.OpenApi.Tests.csproj --filter 'FullyQualifiedNameDocumentTransformerTests|FullyQualifiedNameOperationTransformerTests'

fixes #65723
closes #67457

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5e6eeaef-0254-4489-8007-cb3fe70f7372
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jul 20, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Thanks for your PR, @baywet. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.


var options = new OpenApiOptions();

// While added first, document transformers should run after the operation transformers

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@halter73 Seems like it was very intentional, but I'm fine trying to change it and get feedback. I think we will still want to not do it in 11 as we are late in the release cycle right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This was introduced in #56395 by @martincostello

@baywet
baywet marked this pull request as ready for review July 21, 2026 12:46
@baywet
baywet requested a review from a team as a code owner July 21, 2026 12:46
Copilot AI review requested due to automatic review settings July 21, 2026 12:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates OpenAPI document generation to honor the registration order of document/operation/schema transformers, enabling document transformers registered early to run before operation/path generation (e.g., to pre-populate tag metadata without later discovery overwriting it).

Changes:

  • Track all transformer registrations in a unified internal list (OpenApiOptions.Transformers) while preserving the existing per-type lists.
  • Update OpenApiDocumentService to generate paths at the first non-document transformer registration, allowing earlier document transformers to run pre-generation.
  • Adjust/add tests to validate ordering behavior and the new unified registration list.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/OpenApi/src/Services/OpenApiOptions.cs Adds unified Transformers registration list and appends registrations from each Add*Transformer overload.
src/OpenApi/src/Services/OpenApiDocumentService.cs Applies unified ordering by interleaving document-transformer execution with a “generate paths once” boundary.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Transformers/OpenApiOptionsTests.cs Asserts transformers are also registered into the unified Transformers list.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Transformers/OperationTransformerTests.cs Updates ordering test to reflect the new semantics (document transformers run where registered).
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Transformers/DocumentTransformerTests.cs Adds coverage for pre-generation document transformer behavior and ordering relative to operation transformers.

Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 5e6eeaef-0254-4489-8007-cb3fe70f7372

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Transformers/DocumentTransformerTests.cs:7

  • using Microsoft.AspNetCore.Http; is unused in this test file (all HttpMethod references come from System.Net.Http). With warnings treated as errors, this can break the build; please remove the unused using.
using Microsoft.AspNetCore.Http;

Comment on lines +119 to +127
var hasGenerationTransformers = false;
for (var i = 0; i < _options.Transformers.Count; i++)
{
if (_options.Transformers[i].Kind is not OpenApiTransformerKind.Document)
{
hasGenerationTransformers = true;
break;
}
}
@Youssef1313 Youssef1313 added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Sep 2, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime.
To make sure no conflicting changes have occurred, please rerun validation before merging. You can do this by leaving an /azp run comment here (requires commit rights), or by simply closing and reopening.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Sep 26, 2026

This branch was previously deployed

1 inactive (outdated) deployment
copilot-pat-pool — 7e9ae5fe Deployed Jul 20, 2026 by dotnet-policy-service[bot] via pat_pool #646
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc community-contribution Indicates that the PR has been added by a community member pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pre-generation OpenAPI hook in AddOpenApi options to initialize document metadata

3 participants