Skip to content

Conversation

luoxing66
Copy link

Problem

Modifications made by "SchemaTransformer" to Parameter will not take effect immediately, because "SchemaTransformer" is run when "OpenApiParameter" is constructed, rather than running "SchemaTransformer" first.
image

Solution

Execute "SchemaTransformer" in advance to take effect of parameter changes
image

Fixes #62893

@luoxing66 luoxing66 requested review from a team and captainsafia as code owners July 27, 2025 12:25
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Jul 27, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 27, 2025
Copy link
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

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

Could you add a test for this bug as well? Then it's protected against unintentional regressions in the future.

@martincostello martincostello added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Jul 27, 2025
@luoxing66
Copy link
Author

@dotnet-policy-service agree

@luoxing66
Copy link
Author

Could you add a test for this bug as well? Then it's protected against unintentional regressions in the future.

Ok, added test

@luoxing66 luoxing66 mentioned this pull request Jul 31, 2025
1 task
var options = new OpenApiOptions();
options.AddSchemaTransformer((schema, context, cancellationToken) =>
{
context.ParameterDescription.Name = context.ParameterDescription.Name.ToUpper(CultureInfo.CurrentCulture);
Copy link
Contributor

Choose a reason for hiding this comment

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

The descriptor from the Api Explorer is modified here. Should this not be done on an Operation Transformer?

I would add a warning to not modify the result coming from the Api Explorer.

I think you can set the parameter name with Metadata on minimal apis. Or it's maybe which is missing and should be added as a feature.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, this was my feedback as well in #62893 (comment).

In an ideal world, the ParameterDescription APIs would've been immutable so things like this don't happen but mutating the ParameterDescription is not the correct way to implement this change and we shouldn't change schema transformer application to resolve this issue.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, I found that using Operation Transformer can solve my problem.

Copy link
Author

Choose a reason for hiding this comment

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

It is recommended to add warnings or restrictions not to modify parameters in Schema Transformer.

@luoxing66 luoxing66 closed this Aug 1, 2025
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-rc1 milestone Aug 1, 2025
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 feature-openapi

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OpenApi] SchemaTransformer Bug

4 participants