[HttpGet]
[Route("students")]
[SwaggerOperation(Tags = new[] { "Student" })]
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(ResponseModel<IList<Student>>))]
[SwaggerResponseExample(HttpStatusCode.OK, typeof(StudentResponseExample))]
[SwaggerResponse(HttpStatusCode.InternalServerError)]
public IHttpActionResult SearchStudent()
{
IDictionary<string, string> searchParams = null;
searchParams = ControllerContext.GetQueryStrings();
.
.
.
}
以上API有三个可选参数将被传递作为查询字符串扬鞭 - 网页API - 可选查询参数
- SyncDate -
- 偏移龙 - 诠释
- 极限 - 诠释
用户无法在Swagger UI中输入这些可选查询参数。请指导我实现可选的查询参数。
我正在使用swashbuckle,我更喜欢使用注释,而不是在每个API方法上都有漫长的注释部分来描述Swagger功能。
我提到以下Adding Query String Params to my Swagger Specs和过滤器创建的SwaggerParameterAttribute级Web API的文件夹,并试图给出添加OperationFilter G中lobalConfiguration.Configuration .EnableSwagger时,它抛出一个类型或无法找到名称空间名称SwaggerParametersAttributeHandler。我甚至还添加了筛选器文件夹命名空间,但仍存在错误。
请就如何落实在招摇
谢谢,但在招摇的UI是非常需要的显示器 -
他们将作为可选的,如果你让他们可空类型的治疗。我如何将其更改为可选? –
@TechJerk刚刚更新了我的答案,将空值分配给参数并使其成为可选参数。 –
它像魅力一样工作!谢谢 :) –