Skip to content

Commit b5efc83

Browse files
committed
Fix generated for Href helper for param-less actions
1 parent 17712ec commit b5efc83

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

goagen/gen_app/writers.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,9 @@ func {{ .Unmarshal }}(ctx context.Context, service *goa.Service, req *http.Reque
752752
resourceT = `{{ if .CanonicalTemplate }}// {{ .Name }}Href returns the resource href.
753753
func {{ .Name }}Href({{ if .CanonicalParams }}{{ join .CanonicalParams ", " }} interface{}{{ end }}) string {
754754
{{ range $param := .CanonicalParams }} param{{$param}} := strings.TrimLeftFunc(fmt.Sprintf("%v", {{$param}}), func(r rune) bool { return r == '/' })
755-
{{ end }} return fmt.Sprintf("{{ .CanonicalTemplate }}", param{{ join .CanonicalParams ", param" }})
756-
}
755+
{{ end }}{{ if .CanonicalParams }} return fmt.Sprintf("{{ .CanonicalTemplate }}", param{{ join .CanonicalParams ", param" }})
756+
{{ else }} return "{{ .CanonicalTemplate }}"
757+
{{ end }}}
757758
{{ end }}`
758759

759760
// mediaTypeT generates the code for a media type.

goagen/gen_app/writers_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,22 @@ var _ = Describe("HrefWriter", func() {
905905
Ω(written).Should(ContainSubstring(simpleResourceHref))
906906
})
907907
})
908+
909+
Context("and a canonical action with no param", func() {
910+
BeforeEach(func() {
911+
canoTemplate = "/bottles"
912+
})
913+
914+
It("writes the href method", func() {
915+
err := writer.Execute(data)
916+
Ω(err).ShouldNot(HaveOccurred())
917+
b, err := ioutil.ReadFile(filename)
918+
Ω(err).ShouldNot(HaveOccurred())
919+
written := string(b)
920+
Ω(written).ShouldNot(BeEmpty())
921+
Ω(written).Should(ContainSubstring(noParamHref))
922+
})
923+
})
908924
})
909925
})
910926
})
@@ -1481,5 +1497,9 @@ type BottlesController interface {
14811497
paramid := strings.TrimLeftFunc(fmt.Sprintf("%v", id), func(r rune) bool { return r == '/' })
14821498
return fmt.Sprintf("/bottles/%v", paramid)
14831499
}
1500+
`
1501+
noParamHref = `func BottleHref() string {
1502+
return "/bottles"
1503+
}
14841504
`
14851505
)

0 commit comments

Comments
 (0)