关于定义的端点参数获得元数据的最通用方法是什么?
我们可以定义某些端点参数应从查询字符串绑定:[fromquery(name =“ SomeParamName”)]
。
此映射信息是否存储在端点元数据中?
我想确保为端点定义传递的查询字符串参数
[HttpGet("foo")]
public IActionResult Foo([FromQuery("foo-param")]string param)
{
...
}
[HttpGet("bar")]
public IActionResult Bar()
{
...
}
。代码>是一个预期的 但是,对于/bar?foo-param =某物
url foo-param
是外国的。
对于控制器端点,我可以找到ContranterActionDescriptor
元数据条目,该条目具有参数
带有bindingInfo
包含所有我需要的数据的收集。
但是,对于映射的端点,我仅获得请求委托信息。
当然,我可以从委托的target
方法中获取parameterInfo
对象,然后检查[FORFORQUERY]
属性等等,依此类推,但这是一个相当的许多低级样板代码。 我还看到,端点Sapiexplorer扩展了此信息,并宣传生成了正确的文档。因此,我认为Sohuld是获取有关端点参数的信息的通用方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论