我正在嘗試使用我創(chuàng)建的結(jié)構(gòu),并在代碼中用作參數(shù),但是在運(yùn)行后,我收到以下錯(cuò)誤:swag initParseComment error in file /src/handler/handler.go :can not find schema type: "handler.component"我的結(jié)構(gòu):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 {}我也試過(guò),但我得到了完全相同的錯(cuò)誤。// @Param q query types.component true "{'envID':'default', 'podID':'log-gen-6d776dc797-bnbm9', 'follow':false, 'tail':5}"我該如何解決這個(gè)問(wèn)題?
1 回答

慕雪6442864
TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
解決方案是使用(大寫(xiě)C),一切都會(huì)正常工作。types.Component
一些額外的要點(diǎn):
需要任何裝飾器等類型,swagger會(huì)毫無(wú)問(wèn)題地找到結(jié)構(gòu),并且還顯示每個(gè)字段的注釋
要根據(jù)需要定義字段,可以向該字段添加:
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
- 1 回答
- 0 關(guān)注
- 164 瀏覽
添加回答
舉報(bào)
0/150
提交
取消