Swag: A way to specify an empty/nil response body

Created on 29 Jun 2018  路  6Comments  路  Source: swaggo/swag

Is your feature request related to a problem? Please describe.
My api for 404 responses just returns a 404 status code, and for deletes just returns a 204 status code. These responses have no body, and I would like to keep that in the documentation.
Describe the solution you'd like
A way to indicate the status code with no additional response types.
Something like // @Failure 404 nil ?

Describe alternatives you've considered
not document the failure type

Thanks for the library! it's pretty dope.

enhancement

Most helpful comment

Thanks. This way it works now:

// @Success 204 ""

Can you add this to docs?

All 6 comments

Same problem here - tried with {}, [], nil...
Either gives error or shows false content.

As a workaround I just created an empty struct:

type EmptyBody struct { }

Then:

//@Success 204 {object} response.EmptyBody

@Ashtonian @pitw You can use @Success 200 "it's ok" will generate

"responses": {
        "200": {
            "description": "it's ok"
        }
 }

But now don't support no description field,I will fix it to support and add document, thanks for report this issue.

Thanks. This way it works now:

// @Success 204 ""

Can you add this to docs?

@pitw sure, will add to docs later.

Hi, sorry to reply again to this closed issue.

type Response struct {
    Data interface{} `json:"data"`
    Message string `json:"message"`
}
// @Failure 500 {object} Response



md5-8930f4604f5d9e6ba3ca2cb0711b5bac



{
  "data": {},
  "message": "string"
}



md5-4302d1854d7c473b292a8780cedd0377



{
  "data": null,
  "message": "string"
}

Thank you.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chyroc picture chyroc  路  3Comments

Nerzal picture Nerzal  路  6Comments

zhongkeqin picture zhongkeqin  路  4Comments

wingsofovnia picture wingsofovnia  路  3Comments

kirillDanshin picture kirillDanshin  路  3Comments