Disable prefix in model name while swagger client generation

42 Views Asked by At

I am very new to Golang, trying to generate client code in golang

My swagger file has model name as models.BaseModel but the client code contains name as models.ModelsBaseModel

I want to avoid this prefix Models and want the model name as models.BaseModel instead of models.ModelsBaseModel

I am using swagger generate client command with the below template 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}}

In the above code, {{.Schema.GoType}} is the parameter which is generating the model name. Its value is *models.ModelsBaseResponse

Note:

I have already tried stripPackage functions (https://masterminds.github.io/sprig/) and other string functions like replace, trimPrefix, etc but no luck.

1

There are 1 best solutions below

0
Siddharth Kumar Shukla On

{{.Schema.GoType | replace "Models" ""}} This solved the problem