From 9e26c7db0370dba9265b5f59f2b26444e4d41b14 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 19 Feb 2024 03:50:26 +0300 Subject: [PATCH] feat: add cookie parameter to route method --- examples/basic/main.go | 2 +- mux.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/examples/basic/main.go b/examples/basic/main.go index 048a1510..f2bfa420 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -46,7 +46,7 @@ func main() { Message: "Hello, " + data.Name, BestFramework: "Fuego!", }, nil - }).WithDescription("Say hello to the world").AddHeader("test") + }).WithDescription("Say hello to the world").AddHeader("test").AddCookie("test") // Standard net/http handler with automatic OpenAPI route declaration fuego.GetStd(s, "/std", func(w http.ResponseWriter, r *http.Request) { diff --git a/mux.go b/mux.go index 3195ea02..9b3845e0 100644 --- a/mux.go +++ b/mux.go @@ -125,6 +125,14 @@ func (r Route[ResponseBody, RequestBody]) AddHeader(header string) Route[Respons return r } +func (r Route[ResponseBody, RequestBody]) AddCookie(cookie string) Route[ResponseBody, RequestBody] { + r.operation.Parameters = append(r.operation.Parameters, &openapi3.ParameterRef{ + Value: openapi3.NewCookieParameter(cookie), + }) + + return r +} + func (r Route[ResponseBody, RequestBody]) AddTags(tags ...string) Route[ResponseBody, RequestBody] { r.operation.Tags = append(r.operation.Tags, tags...) return r