.net core API可选路由参数
我有一个 .net core api 和 swagger。不,我想添加一个过滤器类,包括可选的过滤器参数。
[HttpGet("", Name ="get-index")]
[ProducesResponseType(typeof(IEnumerable<MyModelGet>), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(void), (int)HttpStatusCode.NoContent)]
public IActionResult GetIndex([FromRoute] MyFilter? filter){
...
}
过滤器类的属性是可选的/nullabel:
public class MyFilter {
public int? size{
get; set;
} = null;
...
}
但在 Swagger 中,所有属性都是必需的:
有什么方法(例如注释)可以使此字段可选吗?
I have a .net core api with swagger. No I want to add a Filter-Class including optional filter-parameters.
[HttpGet("", Name ="get-index")]
[ProducesResponseType(typeof(IEnumerable<MyModelGet>), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(void), (int)HttpStatusCode.NoContent)]
public IActionResult GetIndex([FromRoute] MyFilter? filter){
...
}
The properties of the filter-class are optional/nullabel:
public class MyFilter {
public int? size{
get; set;
} = null;
...
}
But in Swagger all Properties are required:
Is there any way (e.g. a Annotation) to make this fields optional?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用
[FromQuery]
替换[FromRoute]
解决了我的问题。Replacing the
[FromRoute]
by[FromQuery]
solved my issue.