We can define that some of the endpoint parameters should be bound from query string: [FromQuery(Name= "someParamName")]
.
Is this mapping information stored anywhere in endpoint metadata?
I want to ensure that passed query string parameter is defined for the endpoint.
[HttpGet("foo")]
public IActionResult Foo([FromQuery("foo-param")]string param)
{
...
}
[HttpGet("bar")]
public IActionResult Bar()
{
...
}
Here /foo?foo-param=something
is fine, because foo-param
is an expected one,
but for /bar?foo-param=something
url foo-param
is foreign.
For controller endpoints I could locate ControllerActionDescriptor
metadata entry, which has Parameters
collection with BindingInfo
containing all the data I need.
However, for mapped endpoints I get only request delegate information.
Sure, I could get ParameterInfo
objects from delegate's Target
method, and then check for [FromQuery]
attribute, and so on, but it's quite a lot of low-level boilerplate code.
I also see that EndpointsApiExplorer extacts this information and swagger generated correct documentation. Thus I assume there sohuld be a universal way to get the information about endpoint's parameters.