Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 路径中的SwashBulk参数强制为必需_C#_Asp.net Core_Swashbuckle_Swashbuckle.aspnetcore - Fatal编程技术网

C# 路径中的SwashBulk参数强制为必需

C# 路径中的SwashBulk参数强制为必需,c#,asp.net-core,swashbuckle,swashbuckle.aspnetcore,C#,Asp.net Core,Swashbuckle,Swashbuckle.aspnetcore,我遇到了一个问题,如果我试图强制Swashback理解参数是路径的一部分,它会强制它为required [HttpGet] [Route("test/{format}/{baseKey?}")] [Route("test/{format}/{baseKey}/{apiKey}/{year}/{code}/{month}/{includeImages?}")] [Produces("application/json", "app

我遇到了一个问题,如果我试图强制Swashback理解参数是路径的一部分,它会强制它为required

[HttpGet]
[Route("test/{format}/{baseKey?}")]
[Route("test/{format}/{baseKey}/{apiKey}/{year}/{code}/{month}/{includeImages?}")]
[Produces("application/json", "application/xml")]
public async Task<List<TestItem>> Test([FromRoute] string format, [FromRoute] string baseKey, [FromRoute] string apiKey, [FromRoute] string year, [FromRoute] string code, [FromRoute] string month, [FromRoute] bool includeImages = false)
[HttpGet]
[路由(“test/{format}/{baseKey?}”)]
[路由(“test/{format}/{baseKey}/{apiKey}/{year}/{code}/{month}/{includeimage?}”)]
[产生(“应用程序/json”、“应用程序/xml”)]
公共异步任务测试([FromRoute]字符串格式,[FromRoute]字符串基键,[FromRoute]字符串apiKey,[FromRoute]字符串年,[FromRoute]字符串代码,[FromRoute]字符串月,[FromRoute]bool includeImage=false)
但即使标记为
=false
的项目仍按要求标记。 除此之外,.net core在其路径中使用了
来定义非必需项,所以我有点困惑为什么Swashback不尊重这一点

有什么想法吗?

我已经翻遍了这本书,并找到了它 我需要从NuGet安装
swashback.AspNetCore.Annotations
然后将其添加到startup.cs:

services.AddSwaggerGen(c =>
{
   ...
   c.EnableAnnotations();
});
然后执行以下类似操作:

[HttpGet]
public IActionResult GetProducts([FromQuery, SwaggerParameter("Search keywords", Required = true)] string keywords)