jsend协议Swagger定义



Jsend协议是如何在REST API中格式化json响应的简单"标准"。https://github.com/omniti-labs/jsend

我正在使用生成Swagger文档https://github.com/swaggo/swag但是我很难弄清楚如何使用声明性注释格式来描述Jsend响应。

如果有人这样做过,我将非常感谢他们如何使用swag声明性注释格式定义jsend响应的示例片段。

我通过切换到更容易处理语法的goswager.io解决了这个问题。这些是用于基本jsend类型的模型。对于其他响应,我用相关事件结构的名称替换了Data元素,其余的由swagger完成

// Success: no response data required
// swagger:response responseSuccess
type responseSuccess struct {
// in: body
Body struct {
// enum: success
Status string      `json:"status"`
Data   interface{} `json:"data"`
} `json:"body"`
}
// Error: Incorrect use of the API or the requested data is not available
// swagger:response responseError
type responseError struct {
// in: body
Body struct {
// enum: error
Status  string      `json:"status"`
Data    interface{} `json:"data"`
Message string      `json:"message"`
} `json:"body"`
}
// Fail: Backend or system failure.
// swagger:response responseFail
type responseFail struct {
// in: body
Body struct {
// enum: fail
Status  string      `json:"status"`
Data    interface{} `json:"data"`
Message string      `json:"message"`
} `json:"body"`
}

最新更新