diff --git a/pkg/codegen/templates/param-types.tmpl b/pkg/codegen/templates/param-types.tmpl index b35cce5d7c..f49ba3010b 100644 --- a/pkg/codegen/templates/param-types.tmpl +++ b/pkg/codegen/templates/param-types.tmpl @@ -1,6 +1,6 @@ {{range .}}{{$opid := .OperationId}} {{range .TypeDefinitions}} // {{.TypeName}} defines parameters for {{$opid}}. -type {{.TypeName}} {{.Schema.TypeDecl}} +type {{.TypeName}} {{if and (opts.AliasTypes) (.CanAlias)}}={{end}} {{.Schema.TypeDecl}} {{end}} {{end}} diff --git a/pkg/codegen/templates/request-bodies.tmpl b/pkg/codegen/templates/request-bodies.tmpl index cec74bcb0d..313dd11bf4 100644 --- a/pkg/codegen/templates/request-bodies.tmpl +++ b/pkg/codegen/templates/request-bodies.tmpl @@ -1,6 +1,8 @@ {{range .}}{{$opid := .OperationId}} {{range .Bodies}} -// {{$opid}}RequestBody defines body for {{$opid}} for application/json ContentType. -type {{$opid}}{{.NameTag}}RequestBody {{.TypeDef}} +{{with .TypeDef $opid}} +// {{.TypeName}} defines body for {{$opid}} for application/json ContentType. +type {{.TypeName}} {{if and (opts.AliasTypes) (.CanAlias)}}={{end}} {{.Schema.TypeDecl}} +{{end}} {{end}} {{end}} diff --git a/pkg/codegen/templates/templates.gen.go b/pkg/codegen/templates/templates.gen.go index 770ba76fd4..00161ac02d 100644 --- a/pkg/codegen/templates/templates.gen.go +++ b/pkg/codegen/templates/templates.gen.go @@ -723,7 +723,7 @@ func GetSwagger() (*openapi3.Swagger, error) { "param-types.tmpl": `{{range .}}{{$opid := .OperationId}} {{range .TypeDefinitions}} // {{.TypeName}} defines parameters for {{$opid}}. -type {{.TypeName}} {{.Schema.TypeDecl}} +type {{.TypeName}} {{if and (opts.AliasTypes) (.CanAlias)}}={{end}} {{.Schema.TypeDecl}} {{end}} {{end}} `, @@ -757,8 +757,10 @@ func RegisterHandlers(router EchoRouter, si ServerInterface) { `, "request-bodies.tmpl": `{{range .}}{{$opid := .OperationId}} {{range .Bodies}} -// {{$opid}}RequestBody defines body for {{$opid}} for application/json ContentType. -type {{$opid}}{{.NameTag}}RequestBody {{.TypeDef}} +{{with .TypeDef $opid}} +// {{.TypeName}} defines body for {{$opid}} for application/json ContentType. +type {{.TypeName}} {{if and (opts.AliasTypes) (.CanAlias)}}={{end}} {{.Schema.TypeDecl}} +{{end}} {{end}} {{end}} `, @@ -772,7 +774,7 @@ type ServerInterface interface { `, "typedef.tmpl": `{{range .Types}} // {{.TypeName}} defines model for {{.JsonName}}. -type {{.TypeName}} {{.Schema.TypeDecl}} +type {{.TypeName}} {{if and (opts.AliasTypes) (.CanAlias)}}={{end}} {{.Schema.TypeDecl}} {{- if gt (len .Schema.EnumValues) 0 }} // List of {{ .TypeName }} const ( diff --git a/pkg/codegen/templates/typedef.tmpl b/pkg/codegen/templates/typedef.tmpl index 170984fb17..969d7cdea0 100644 --- a/pkg/codegen/templates/typedef.tmpl +++ b/pkg/codegen/templates/typedef.tmpl @@ -1,6 +1,6 @@ {{range .Types}} // {{.TypeName}} defines model for {{.JsonName}}. -type {{.TypeName}} {{.Schema.TypeDecl}} +type {{.TypeName}} {{if and (opts.AliasTypes) (.CanAlias)}}={{end}} {{.Schema.TypeDecl}} {{- if gt (len .Schema.EnumValues) 0 }} // List of {{ .TypeName }} const (