-
Notifications
You must be signed in to change notification settings - Fork 10.3k
EndpointMetadataApiDescriptionProvider Misses Route Parameters #41773
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
Comments
Triage: We should look at doing something similar to MVC
where we still set the ApiParameterDescription when there isn't a parameter in the delegate.
Second, we need to think about the |
@BrennanConroy I don't need a date, but will this be patched in 6.0? I need to provide guidance to customers around how to address this situation in the interim. |
Thanks for contacting us. We're moving this issue to the |
I don't necessarily agree with this perspective. The way I see it, the method signature should be the source of truth for API annotations about a particular endpoint, not the route parameter. @commonsensesoftware Have you looked into leveraging route groups (.NET 7) in the API versioning package at all? It might help alleviate the particular issue here. I'm imagining that calling: ApiVersion apiV1 = new ApiVersion(1); Would great a cc: @halter73 |
@captainsafia Unfortunately, the source of truth is not the method signature. HTTP is the API. C#, just like any other language, has an impedance mismatch. It's no different than the incongruence between C# (say - a la EF) and SQL. There are just some things that cannot be expressed in C# because it's not HTTP. An API version is special in terms of how it matches up in the code. The call site (e.g. method) not necessarily have to be present for the endpoint to be invoked. This is the same as the API authors need to describe their APIs terms of HTTP because that's how their clients will call them. An author trusts that API Versioning will call the correct endpoint so they may not have any interest in declaring the code parameter because it would never be used. However, a client needs to know which parameters they can specify, which might be more than one (ex: header and query string). A route group will not address this specific issue. Grouping constructs are useful and will be integrated into API Versioning, but it won't help here. As it stands, an There's really no compelling reason to not have to two flavors of API Explorer be incongruent. This is a violation of POLA. It is completely reasonable that a route parameter can exist that isn't defined in the method signature. Furthermore, any unknown route parameter value can always default to using the parameter name defined in the parsed template and assume the value is a |
Thanks for contacting us. We're moving this issue to the |
@adityamandaleeka, this was in the .NET 8 Planning milestone but it's in the servicing project board. I've removed the milestone so your team can decide where this should go. |
Is there an existing issue for this?
Describe the bug
EndpointMetadataApiDescriptionProvider
misses creatingApiDescriptionParameter
instances that are defined asBindingSource.Custom
orBindingSource.Special
. As seen here,EndpointMetadataApiDescriptionProvider
only considers parameter candidates via theParameterInfo
acquired through Reflection.Some
BindingSource.Special
parameters should be ignored, such asCancellationToken
. API Versioning defines theApiVersion
asBindingSource.Special
because the value can typically come from one or more places (even zero is technically possible). The value ofApiVersion
is set and retrieved throughIApiVersioningFeature
.This behavior is a deviation from
DefaultApiDescriptionProvider
, which considers and creates anApiParameterDescription
for route parameters, even if they don't have a formalParameterInfo
partner (as seen here).Declaring the formal parameter
ApiVersion version
will not work becauseTryParse
is delegated toIApiVersionParser
so that a developer can opt to change the behavior if they want to. Parsing the value at this point in the pipeline is also too late and affects routing or would result in parsing the value more than once.Ultimately,
EndpointMetadataApiDescriptionProvider
should create anApiParameterDescription
for every route parameter in theRoutePattern
(e.g. template); regardless of whether there is a corresponding method parameter.Expected Behavior
EndpointMetadataApiDescriptionProvider
should have parity withDefaultApiDescriptionProvider
wherever possible (obviously modeling binding isn't available for Minimal APIs).Consider the following:
This should produce
ApiDescription.RelativePath
withv1/weatherforecast/{city}
, but instead producesv{version}/weatherforecast/{city}
. Worse still, there is noApiParameterDescription
for{version}
. API Versioning relies on the existence of the parameter description and substitutes the token in the template with the corresponding API version value.This behavior can be reproduced without API Versioning from a pure API Explorer perspective, but the API will not be reachable since the route parameter wouldn't be matched.
Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
6.0.300
Anything else?
This was first reported in dotnet/aspnet-api-versioning#830.
ASP.NET Core 6.0
The text was updated successfully, but these errors were encountered: