-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Support multiple calls to WithTags in WithOpenApi #41779
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.
I'm generally fine with this although this change in behavior does prompt a consideration on naming.
With the advent of AddFilter
, we set a standard that the WithX
model would be used for metadata that could only be set once and the AddX
model would be used with metadata that was additive and didn't follow the "last in wins" principle of other metadata.
Accounting for this API note does make the change a little bit bigger but has the benefit of being consisting with our naming philosophy elsewhere (although AddFilter
is the only real place where it applies at the moment).
This is a really good point. I agree we should do something before .NET 7 to be more consistent here. Unfortunately, Even though the other When we originally considering the
|
Ah, I wasn't think about this precedence when adding the
|
I've been thinking about this change some more. Do you want tags to always be additive? For example, will there ever be a situation where a controller or group specifies tags with "WithTags", and actions/APIs then replace the tags? With this change the tags will always be merged together. An action/API can never replace its parent's tags. |
This is a problem. I want to be able to say that Unfortunately, even though groups add metadata earlier in the list sequentially than metadata added by the specific endpoint, the endpoint-specific metadata is added first temporally. I called out exactly this problem when I added aspnetcore/src/Http/Routing/src/RouteGroupBuilder.cs Lines 107 to 115 in c08123a
No one really discussed this in the PR though, and I'm not sure if there's a good way to improve this. Do you have any ideas @JamesNK? Do you think we should add API for extension methods that are group-aware so they can override things like a groups tags? |
Another option might be to add something like |
I haven't looked closely at what you're doing in Minimal APIs but I would have expected that group/endpoint would behave the same as controllers/actions. Devs can apply metadata on a controller and it's automatically used by all actions, but actions can override if they choose to, e.g. a There are very few places where |
The trickiness with Unfortunately, this means that the metadata from the "inner" That's why I suggest adding a new API. For example, public abstract class EndpointDataSource
{
+ IReadOnlyList<Endpoint> GetEndpointsForGroup(RoutePattern prefix, IEnumerable<Action<EndpointBuilder>> conventions);
} It might be better as an interface so we could easily check which I don't see another great way to let existing conventions "see" metadata from outer groups without updating all the conventions themselves. In practice, I suspect most of the |
Currently, if you call
.WithTags()
multiple times on an endpoint, only the last call shows up in the generated OpenApiOperation. This isn't a big deal today because you can just call.WithTags()
with multiple parameters, but I imagine this will be more important once we add the group support described in #41428.