Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProducesResponseType Type return for empty return

What is the typeof return to indicate there is empty body return. For example 401 unauthorized returns no body response except 401 status code. [ProducesResponseType(StatusCodes.Status401Unauthorized)) is showing returning the following in swagger example

{
  "type": "string",
  "title": "string",
  "status": 0,
  "detail": "string",
  "instance": "string",
  "additionalProp1": {},
  "additionalProp2": {},
  "additionalProp3": {}
}
like image 633
p0_G Avatar asked Mar 24 '26 20:03

p0_G


1 Answers

I know I'm late to the party on this one, but you can add typeof(void) to the ProducesResponseType like so:

[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]

This worked for me and is no longer showing a response body in Swagger.

like image 87
MrDKOz Avatar answered Mar 27 '26 09:03

MrDKOz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!