【问题标题】:Need help in swagger UI genration on my go program在我的 Go 程序中需要帮助生成大张旗鼓的 UI
【发布时间】:2021-09-07 22:34:36
【问题描述】:

我是 Golang 和 API 的新手。

我们的服务文件包含

getBookHistory(context Context, book string)([]*model.lookuprecord, error){
//some code
}

在我的 rest.go(处理程序)中

// GetBookHistoryLookup godoc
// @Summary Shows historic detailed  Info.
// @Description get history details from the  table in the database.
// @Param book path string true "book"
// @Produce  json
// @Success 200 {object} iModel.LookupRecord
// @Router /history/{book} [get] 
func(h handler) GetBookHistoryLookup(c echo.Context){
//some code
}

我正在使用 github.com/swago/swag/cmd/swag 库。

它会生成一个 swaggerUI,但此获取服务的响应为空。 可以看到返回类型是数组,需要换行

// @Success 200 {object} iModel.LookupRecord

谢谢

【问题讨论】:

  • 你能分享*model.lookuprecord struct吗。
  • @OmkeshSajjanwar - type LookupRecord struct { ID int64 json:"id" db:"id" goqu:"skipinsert"` Iat time.Time json:"iat" db:"iat" Identifier string json:"identifier,omitempty" db:"identifier" Record *Result json:"record,omitempty" db:"result_set" }`

标签: go swagger-ui


【解决方案1】:
// @Success 200 {object} iModel.LookupRecord

替换为

// @Success 200 {object} []iModel.LookupRecord

【讨论】:

    猜你喜欢
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多