我对 Golang 很陌生,正在尝试在 golang 中生成客户端代码
我的 swagger 文件的模型名称为 models.BaseModel,但客户端代码包含名称为 models.ModelsBaseModel
我想避免使用此前缀 Models 并希望模型名称为 models.BaseModel 而不是 models.ModelsBaseModel
我正在使用带有以下模板的 swagger 生成客户端命令 https://github.com/go-swagger/go-swagger/blob/master/generator/templates/client/response.gotmpl
Payload {{ if and (not .Schema.IsBaseType) (not .Schema.IsInterface) .Schema.IsComplexObject (not .Schema.IsStream) }}*{{ end }}{{ if (not .Schema.IsStream) }}{{.Schema.GoType}}{{ else }}io.Writer{{end}}
在上面的代码中,{{.Schema.GoType}}是生成模型名称的参数。 它的值是 *models.ModelsBaseResponse
注:
我已经尝试过 stripPackage 函数(https://masterminds.github.io/sprig/)和其他字符串函数,如替换、trimPrefix 等,但没有运气。
{{.Schema.GoType |替换“模型”“”}} 这解决了问题