I'm trying to find a way to set a string parameter to be required on a ASP.NET Core Api project but haven't been able to figure it out. My assumption was just adding the DataAnnotation of [Required] would work, but this is not the case.
How does one get Swagger to realize a query string parameter of type string is required?
[HttpGet]
[Produces("application/json", Type = typeof(IEnumerable<string>))]
[SwaggerOperation(operationId: "ListStuff")]
[ProducesResponseType(typeof(string), (int)HttpStatusCode.BadRequest)]
public IActionResult ListStuff(int id, [Required]string auditId)
{
...
}
With above code, the required flag is still false in the Swagger.json file:
{
"name":"auditId",
"in":"query",
"required":false,
"type":"string"
}