swag icon indicating copy to clipboard operation
swag copied to clipboard

Result is nil, @Success 200 {object} gin.H {"msg": "","data": "","code": 200}

Open WangSongsen opened this issue 4 years ago • 4 comments
trafficstars

I write such an interface and return gin.H{} Screenshot below: image

but this struct is nil . I made a mistake myself, I hope to get your answer image

WangSongsen avatar May 17 '21 12:05 WangSongsen

Excuse me, how did you solve it ?

lifegit avatar Jul 16 '21 03:07 lifegit

Demo

lifegit avatar Jul 16 '21 03:07 lifegit

@success 200 {object} jsonresult.JSONResult{data=nil} "desc"

data should be nil, nil will be json null

but this feature does not work

ethantsien avatar Jun 21 '22 03:06 ethantsien

OAS defines the data types, not values.

type JSONResult struct {
    Code    int          `json:"code" `
    Message string       `json:"message"`
    Data    interface{}  `json:"data"`
}

The annotation @success 200 {object} jsonresult.JSONResult{data=proto.Order} "desc" will define the type for JSONResult.Data as been a proto.Order. The OAS model definition will look like this:

type JSONResult struct {
    Code    int          `json:"code" `
    Message string       `json:"message"`
    Data    proto.Order  `json:"data"`
}

ubogdan avatar Jun 21 '22 06:06 ubogdan