Skip to content

Commit 1ef78fc

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 554b42b commit 1ef78fc

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

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 .Schema.IsRef (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 .Schema.IsRef (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 .Schema.IsRef (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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy