UncountedBrute
UncountedBrute

Reputation: 506

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.

[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. Further to this, .net core used ? in it's routes to define a non-required item so I'm a little confused why Swashbuckle doesn't respect this.

Any ideas?

Upvotes: 0

Views: 541

Answers (1)

UncountedBrute
UncountedBrute

Reputation: 506

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:

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

Then do similar to the following:

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

Upvotes: 1

Related Questions