为了账号安全,请及时绑定邮箱和手机立即绑定

gin-swagger 找不到架构类型:“handler.component”

gin-swagger 找不到架构类型:“handler.component”

Go
繁星淼淼 2022-08-15 15:59:06
我正在尝试使用我创建的结构,并在代码中用作参数,但是在运行后,我收到以下错误:swag initParseComment error in file /src/handler/handler.go :can not find schema type: "handler.component"我的结构:package types// Component defines the structure of the json that user will send for a log search// swagger:parameters componenttype Component struct {    // in: query    // example: {"envID":"default", "podID":"log-gen-6d776dc797-bnbm9", "follow":false, "tail":5}    EnvID  string `json:"envID"`  // The env-id    PodID  string `json:"podID"`  // The podID    Tail   int    `json:"tail"`   // Number of lines for tailing the logs    Follow bool   `json:"follow"` // If the we want to follow the logs or not    Site   string `json:"site"`   // The cluster/site which hosts the component --> local is pointing to the local cluster}我的处理程序:package handlerimport (    "src/types")// FollowLogsSSE is ...// @Summary Return logs// @Accept  json// @Produce  json// @Param q query component true "{'envID':'default', 'podID':'log-gen-6d776dc797-bnbm9', 'follow':false, 'tail':5}"// @Success 200 {object} string stringfunc FollowLogsSSE(comp types.Component) gin.HandlerFunc {}我也试过,但我得到了完全相同的错误。// @Param q query types.component true "{'envID':'default', 'podID':'log-gen-6d776dc797-bnbm9', 'follow':false, 'tail':5}"我该如何解决这个问题?
查看完整描述

1 回答

?
慕雪6442864

TA贡献1812条经验 获得超5个赞

解决方案是使用(大写C),一切都会正常工作。types.Component

一些额外的要点:

  • 需要任何装饰器等类型,swagger会毫无问题地找到结构,并且还显示每个字段的注释

  • 要根据需要定义字段,可以向该字段添加:binding:"required"

    EnvID  string `json:"envID" binding:"required"` // The env-id: this can be an env that has created by the user or any other K8s namespace


查看完整回答
反对 回复 2022-08-15
  • 1 回答
  • 0 关注
  • 140 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号