-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix:Modifications made by SchemaTransformer to Parameters do not take effect immediately #62951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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.
@dotnet-policy-service agree |
Ok, added test |
var options = new OpenApiOptions(); | ||
options.AddSchemaTransformer((schema, context, cancellationToken) => | ||
{ | ||
context.ParameterDescription.Name = context.ParameterDescription.Name.ToUpper(CultureInfo.CurrentCulture); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.

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

Fixes #62893