简体   繁体   English

路径中的 Swashbuckle 参数强制为必需

[英]Swashbuckle parameters in path forced to required

I am having an issue where if I try to force swashbuckle to understand the parameter is part of the path, it forces it to required.我遇到了一个问题,如果我试图强制 swashbuckle 理解参数是路径的一部分,它会强制它为必需的。

[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)

But even the item that is marked with = false is still marked as required.但即使是用= false标记的项目,仍然是按要求标记的。 Further to this, .net core used ?除此之外,使用了 .net 内核? in it's routes to define a non-required item so I'm a little confused why Swashbuckle doesn't respect this.在定义非必需项目的路线中,所以我有点困惑为什么 Swashbuckle 不尊重这一点。

Any ideas?有任何想法吗?

I have dug through the documentation of swashbuckle and have identified that I need to install the Swashbuckle.AspNetCore.Annotations from NuGet Then add this to startup.cs:我已经翻阅了swashbuckle 的文档,并确定我需要从 NuGet 安装Swashbuckle.AspNetCore.Annotations然后将其添加到 startup.cs:

services.AddSwaggerGen(c =>
{
   ...
   c.EnableAnnotations();
});

Then do similar to the following:然后执行类似以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM