我有一個帶有 swagger 檔案生成的 go web 應用程式。最近在我的專案中添加了新的端點,它在 POST 和 PUT 請求中使用以下結構:
Secret struct {
// Secret unique key name.
Name string `json:"name" example:"ACCESS_TOKEN"`
// type: string
// x-go-type: "string"
Value json.RawMessage `json:"value" swagger:"type:string"`
// Tags in which this secret is used.
Tags []string `json:"tags" example:"dev,prod,omitempty"`
}
當我嘗試使用命令構建 swagger 檔案時:swag init -md ./documentation -o ./swagger
我收到以下錯誤:

如果我理解正確,應該添加type definition explicitly,但我不明白如何正確定義型別,所有評論組合都不起作用。此問題與json.RawMessage型別(值欄位)有關,因為如果我用 interface{} 替換此型別,一切正常。
uj5u.com熱心網友回復:
我找到了解決我的問題的方法,以前我必須省略使用,--parseDependency因為 swagger doc generation 掛起但如果我同時傳遞--parseDepth1 我的 docs 成功生成,所以一個完整的 cmd 是:
swag init --parseDependency --parseInternal --parseDepth 1 -md ./documentation -o ./swagger
據我了解,這是因為json.RawMessage 需要匯入,但如果我不使用--parseDependencyjson.RawMessage 型別,則無法找到,但在我的問題案例中,單個 --parseDependency 掛起,因此無法使用。解決方案是使用--parseDepth引數
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/393695.html
