From 0d50afac8e77bb0a752012cc57ba4929f7ed1682 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Sun, 24 Sep 2023 21:48:00 -0700 Subject: [PATCH] Handle lack of parameters --- cmd/gen/generator/routes.go | 14 ++++++++++---- types/types.go | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/gen/generator/routes.go b/cmd/gen/generator/routes.go index 2ba9286..b9bd8f2 100644 --- a/cmd/gen/generator/routes.go +++ b/cmd/gen/generator/routes.go @@ -26,10 +26,12 @@ func (r *RoutesGenerator) Generate(routes []extractor.Route) error { f.Comment(r.Summary) f.Func().Params( jen.Id("c").Id("*Client"), - ).Id(transformName(r.Name)).Params( - jen.Id("ctx").Qual("context", "Context"), - jen.Id("data").Qual("go.elara.ws/go-lemmy/types", r.ParamsName), - ).ParamsFunc(func(g *jen.Group) { + ).Id(transformName(r.Name)).ParamsFunc(func(g *jen.Group) { + g.Id("ctx").Qual("context", "Context") + if r.ParamsName != "" { + g.Id("data").Qual("go.elara.ws/go-lemmy/types", r.ParamsName) + } + }).ParamsFunc(func(g *jen.Group) { if r.ReturnName != "" { g.Op("*").Qual("go.elara.ws/go-lemmy/types", r.ReturnName) } @@ -40,6 +42,10 @@ func (r *RoutesGenerator) Generate(routes []extractor.Route) error { returnName = "EmptyResponse" } + if r.ParamsName == "" { + g.Id("data").Op(":=").Qual("go.elara.ws/go-lemmy/types", "EmptyData").Block() + } + g.Id("resData").Op(":=").Op("&").Qual("go.elara.ws/go-lemmy/types", returnName).Block() var funcName string diff --git a/types/types.go b/types/types.go index 7ea2f69..c8edabc 100644 --- a/types/types.go +++ b/types/types.go @@ -11,6 +11,10 @@ type EmptyResponse struct { LemmyResponse } +type EmptyData struct { + Auth string `json:"auth" url:"auth,omitempty"` +} + type LemmyResponse struct { Error Optional[string] `json:"error" url:"error,omitempty"` }