Skip to content

Commit 71813ff

Browse files
committed
Fix: Don't use type aliases with external references
In the case that we're referencing a type defined in an external package, using an alias here results in build errors i.e.: ./api.gen.go:93:7: cannot define new methods on non-local type common.TypeNameHere Instead, we can make sure we only alias when there's not an external reference in use, using the new `Schema.IsExternalRef` function.
1 parent 7f960ff commit 71813ff

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

pkg/codegen/templates/strict/strict-fiber-interface.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
type {{$receiverTypeName}} struct{ {{$ref}}{{.NameTagOrContentType}}Response }
4949
{{end}}
5050
{{else if and (not $hasHeaders) ($fixedStatusCode) (.IsSupported) -}}
51-
type {{$receiverTypeName}} {{if eq .NameTag "Multipart"}}func(writer *multipart.Writer)error{{else if .IsSupported}}{{if .Schema.IsRef}}={{end}} {{.Schema.TypeDecl}}{{else}}io.Reader{{end}}
51+
type {{$receiverTypeName}} {{if eq .NameTag "Multipart"}}func(writer *multipart.Writer)error{{else if .IsSupported}}{{if and (not .Schema.IsExternalRef)}}={{end}} {{.Schema.TypeDecl}}{{else}}io.Reader{{end}}
5252
{{else -}}
5353
type {{$receiverTypeName}} struct {
5454
Body {{if eq .NameTag "Multipart"}}func(writer *multipart.Writer)error{{else if .IsSupported}}{{.Schema.TypeDecl}}{{else}}io.Reader{{end}}

pkg/codegen/templates/strict/strict-interface.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
type {{$receiverTypeName}} struct{ {{$ref}}{{.NameTagOrContentType}}Response }
5151
{{end}}
5252
{{else if and (not $hasHeaders) ($fixedStatusCode) (.IsSupported) -}}
53-
type {{$receiverTypeName}} {{if eq .NameTag "Multipart"}}func(writer *multipart.Writer)error{{else if .IsSupported}}{{if .Schema.IsRef}}={{end}} {{.Schema.TypeDecl}}{{else}}io.Reader{{end}}
53+
type {{$receiverTypeName}} {{if eq .NameTag "Multipart"}}func(writer *multipart.Writer)error{{else if .IsSupported}}{{if and (not .Schema.IsExternalRef)}}={{end}} {{.Schema.TypeDecl}}{{else}}io.Reader{{end}}
5454
{{else -}}
5555
type {{$receiverTypeName}} struct {
5656
Body {{if eq .NameTag "Multipart"}}func(writer *multipart.Writer)error{{else if .IsSupported}}{{.Schema.TypeDecl}}{{else}}io.Reader{{end}}

pkg/codegen/templates/strict/strict-iris-interface.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
type {{$receiverTypeName}} struct{ {{$ref}}{{.NameTagOrContentType}}Response }
5151
{{end}}
5252
{{else if and (not $hasHeaders) ($fixedStatusCode) (.IsSupported) -}}
53-
type {{$receiverTypeName}} {{if eq .NameTag "Multipart"}}func(writer *multipart.Writer)error{{else if .IsSupported}}{{if .Schema.IsRef}}={{end}} {{.Schema.TypeDecl}}{{else}}io.Reader{{end}}
53+
type {{$receiverTypeName}} {{if eq .NameTag "Multipart"}}func(writer *multipart.Writer)error{{else if .IsSupported}}{{if and (not .Schema.IsExternalRef)}}={{end}} {{.Schema.TypeDecl}}{{else}}io.Reader{{end}}
5454
{{else -}}
5555
type {{$receiverTypeName}} struct {
5656
Body {{if eq .NameTag "Multipart"}}func(writer *multipart.Writer)error{{else if .IsSupported}}{{.Schema.TypeDecl}}{{else}}io.Reader{{end}}

0 commit comments

Comments
 (0)