It would be great, if it was possible to write [SwaggerResponse(HttpStatusCode.BadRequest)] instead of [SwaggerResponse(400)]. For example
[SwaggerResponse(HttpStatusCode.BadRequest)]
public async Task<IActionResult> MyMethod(MyModel model)
{
if (!ModelState.IsValid)
return BadRequest();
...
would be more readable than
[SwaggerResponse(400)]
public async Task<IActionResult> MyMethod(MyModel model)
{
if (!ModelState.IsValid)
return BadRequest();
...
as you can directly see that the [SwaggerResponse(HttpStatusCode.BadRequest)] relates to the return BadRequest();.
This could be achieved by adding a constructor to the SwaggerResponseAttribute that has a System.Net.HttpStatusCode statusCode parameter instead of the int statusCode. System.Net.HttpStatusCode is in System.Net.Primitives which is already (indirectly) referenced by Swashbuckle.SwaggerGen.
I think this makes sense, and PR should be the one line kind.
why not use the StatusCodes constants in Microsoft.AspNetCore.Http?
[SwaggerResponse(StatusCodes.Status400BadRequest)]
they are already ints and you can do it today :)
Simple reason: because I didn't know about them. Thanks for the tip.
Most helpful comment
Simple reason: because I didn't know about them. Thanks for the tip.