我有一个带有 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"`
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用命令构建 swagger 文档时:swag init -md ./documentation -o ./swagger
我收到以下错误:
如果我正确理解应该添加type definition explicitly,但我不明白如何正确定义类型,所有注释组合都不起作用。这个问题与类型(值字段)有关,json.RawMessage因为如果我用 interface{} 替换该类型,一切都会正常。