From 106861ae983535f1500371fcf89ad7c02774e44f Mon Sep 17 00:00:00 2001 From: Gaiaz Iusipov Date: Fri, 28 Jun 2024 14:22:13 +0400 Subject: [PATCH] Avoid extra http.Request allocation --- README.md | 3 +- .../authenticated-api/stdhttp/api/api.gen.go | 10 ++++-- examples/import-mapping/admin/server.gen.go | 3 +- examples/minimal-server/chi/api/ping.gen.go | 3 +- .../minimal-server/gorillamux/api/ping.gen.go | 3 +- .../minimal-server/stdhttp/api/ping.gen.go | 3 +- .../petstore-expanded/chi/api/petstore.gen.go | 12 +++---- .../gorilla/api/petstore.gen.go | 12 +++---- .../stdhttp/api/petstore.gen.go | 12 +++---- .../strict/api/petstore-server.gen.go | 12 +++---- internal/test/issues/issue-1039/server.gen.go | 3 +- internal/test/issues/issue-1087/api.gen.go | 3 +- .../issue-1378/bionicle/bionicle.gen.go | 3 +- .../issue-1378/fooservice/fooservice.gen.go | 3 +- .../gen/spec_base/issue.gen.go | 6 ++-- .../name_normalizer.gen.go | 3 +- .../name_normalizer.gen.go | 3 +- .../to-camel-case/name_normalizer.gen.go | 3 +- .../unset/name_normalizer.gen.go | 3 +- internal/test/server/server.gen.go | 30 ++++++---------- internal/test/strict-server/chi/server.gen.go | 36 +++++++------------ .../test/strict-server/gorilla/server.gen.go | 36 +++++++------------ .../test/strict-server/stdhttp/server.gen.go | 36 +++++++------------ pkg/codegen/templates/chi/chi-middleware.tmpl | 7 ++-- .../templates/gorilla/gorilla-middleware.tmpl | 7 ++-- .../stdhttp/std-http-middleware.tmpl | 7 ++-- 26 files changed, 100 insertions(+), 162 deletions(-) diff --git a/README.md b/README.md index d3fcff5c2f..ab01d54e0b 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,6 @@ type ServerInterface interface { // FindPets operation middleware func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -183,7 +182,7 @@ func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Reque handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // HandlerWithOptions creates http.Handler with additional options diff --git a/examples/authenticated-api/stdhttp/api/api.gen.go b/examples/authenticated-api/stdhttp/api/api.gen.go index 7b1fa2c487..a631cdd8c4 100644 --- a/examples/authenticated-api/stdhttp/api/api.gen.go +++ b/examples/authenticated-api/stdhttp/api/api.gen.go @@ -428,10 +428,13 @@ type MiddlewareFunc func(http.Handler) http.Handler // ListThings operation middleware func (siw *ServerInterfaceWrapper) ListThings(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() ctx = context.WithValue(ctx, BearerAuthScopes, []string{}) + r = r.WithContext(ctx) + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.ListThings(w, r) })) @@ -440,15 +443,18 @@ func (siw *ServerInterfaceWrapper) ListThings(w http.ResponseWriter, r *http.Req handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // AddThing operation middleware func (siw *ServerInterfaceWrapper) AddThing(w http.ResponseWriter, r *http.Request) { + ctx := r.Context() ctx = context.WithValue(ctx, BearerAuthScopes, []string{"things:w"}) + r = r.WithContext(ctx) + handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.AddThing(w, r) })) @@ -457,7 +463,7 @@ func (siw *ServerInterfaceWrapper) AddThing(w http.ResponseWriter, r *http.Reque handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/examples/import-mapping/admin/server.gen.go b/examples/import-mapping/admin/server.gen.go index 66d84690ca..84f881f102 100644 --- a/examples/import-mapping/admin/server.gen.go +++ b/examples/import-mapping/admin/server.gen.go @@ -44,7 +44,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetUserById operation middleware func (siw *ServerInterfaceWrapper) GetUserById(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -65,7 +64,7 @@ func (siw *ServerInterfaceWrapper) GetUserById(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/examples/minimal-server/chi/api/ping.gen.go b/examples/minimal-server/chi/api/ping.gen.go index 3f4b5ce298..a2f368005a 100644 --- a/examples/minimal-server/chi/api/ping.gen.go +++ b/examples/minimal-server/chi/api/ping.gen.go @@ -42,7 +42,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetPing operation middleware func (siw *ServerInterfaceWrapper) GetPing(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.GetPing(w, r) @@ -52,7 +51,7 @@ func (siw *ServerInterfaceWrapper) GetPing(w http.ResponseWriter, r *http.Reques handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/examples/minimal-server/gorillamux/api/ping.gen.go b/examples/minimal-server/gorillamux/api/ping.gen.go index f62e3c7f00..9445d02b53 100644 --- a/examples/minimal-server/gorillamux/api/ping.gen.go +++ b/examples/minimal-server/gorillamux/api/ping.gen.go @@ -33,7 +33,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetPing operation middleware func (siw *ServerInterfaceWrapper) GetPing(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.GetPing(w, r) @@ -43,7 +42,7 @@ func (siw *ServerInterfaceWrapper) GetPing(w http.ResponseWriter, r *http.Reques handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/examples/minimal-server/stdhttp/api/ping.gen.go b/examples/minimal-server/stdhttp/api/ping.gen.go index 6d11afc6ed..3ce4c5e3e1 100644 --- a/examples/minimal-server/stdhttp/api/ping.gen.go +++ b/examples/minimal-server/stdhttp/api/ping.gen.go @@ -33,7 +33,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetPing operation middleware func (siw *ServerInterfaceWrapper) GetPing(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.GetPing(w, r) @@ -43,7 +42,7 @@ func (siw *ServerInterfaceWrapper) GetPing(w http.ResponseWriter, r *http.Reques handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/examples/petstore-expanded/chi/api/petstore.gen.go b/examples/petstore-expanded/chi/api/petstore.gen.go index 89777eba05..88b246f37b 100644 --- a/examples/petstore-expanded/chi/api/petstore.gen.go +++ b/examples/petstore-expanded/chi/api/petstore.gen.go @@ -115,7 +115,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // FindPets operation middleware func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -146,12 +145,11 @@ func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Reque handler = siw.HandlerMiddlewares[i](handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // AddPet operation middleware func (siw *ServerInterfaceWrapper) AddPet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.AddPet(w, r) @@ -161,12 +159,11 @@ func (siw *ServerInterfaceWrapper) AddPet(w http.ResponseWriter, r *http.Request handler = siw.HandlerMiddlewares[i](handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // DeletePet operation middleware func (siw *ServerInterfaceWrapper) DeletePet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -187,12 +184,11 @@ func (siw *ServerInterfaceWrapper) DeletePet(w http.ResponseWriter, r *http.Requ handler = siw.HandlerMiddlewares[i](handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // FindPetByID operation middleware func (siw *ServerInterfaceWrapper) FindPetByID(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -213,7 +209,7 @@ func (siw *ServerInterfaceWrapper) FindPetByID(w http.ResponseWriter, r *http.Re handler = siw.HandlerMiddlewares[i](handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/examples/petstore-expanded/gorilla/api/petstore.gen.go b/examples/petstore-expanded/gorilla/api/petstore.gen.go index 78d2178eab..0ccc7da0b5 100644 --- a/examples/petstore-expanded/gorilla/api/petstore.gen.go +++ b/examples/petstore-expanded/gorilla/api/petstore.gen.go @@ -87,7 +87,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // FindPets operation middleware func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -118,12 +117,11 @@ func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Reque handler = siw.HandlerMiddlewares[i](handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // AddPet operation middleware func (siw *ServerInterfaceWrapper) AddPet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.AddPet(w, r) @@ -133,12 +131,11 @@ func (siw *ServerInterfaceWrapper) AddPet(w http.ResponseWriter, r *http.Request handler = siw.HandlerMiddlewares[i](handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // DeletePet operation middleware func (siw *ServerInterfaceWrapper) DeletePet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -159,12 +156,11 @@ func (siw *ServerInterfaceWrapper) DeletePet(w http.ResponseWriter, r *http.Requ handler = siw.HandlerMiddlewares[i](handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // FindPetByID operation middleware func (siw *ServerInterfaceWrapper) FindPetByID(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -185,7 +181,7 @@ func (siw *ServerInterfaceWrapper) FindPetByID(w http.ResponseWriter, r *http.Re handler = siw.HandlerMiddlewares[i](handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/examples/petstore-expanded/stdhttp/api/petstore.gen.go b/examples/petstore-expanded/stdhttp/api/petstore.gen.go index 23dd9d4639..733981ff92 100644 --- a/examples/petstore-expanded/stdhttp/api/petstore.gen.go +++ b/examples/petstore-expanded/stdhttp/api/petstore.gen.go @@ -88,7 +88,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // FindPets operation middleware func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -119,12 +118,11 @@ func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Reque handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // AddPet operation middleware func (siw *ServerInterfaceWrapper) AddPet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.AddPet(w, r) @@ -134,12 +132,11 @@ func (siw *ServerInterfaceWrapper) AddPet(w http.ResponseWriter, r *http.Request handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // DeletePet operation middleware func (siw *ServerInterfaceWrapper) DeletePet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -160,12 +157,11 @@ func (siw *ServerInterfaceWrapper) DeletePet(w http.ResponseWriter, r *http.Requ handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // FindPetByID operation middleware func (siw *ServerInterfaceWrapper) FindPetByID(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -186,7 +182,7 @@ func (siw *ServerInterfaceWrapper) FindPetByID(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/examples/petstore-expanded/strict/api/petstore-server.gen.go b/examples/petstore-expanded/strict/api/petstore-server.gen.go index 656f40d906..f1ba3d6d44 100644 --- a/examples/petstore-expanded/strict/api/petstore-server.gen.go +++ b/examples/petstore-expanded/strict/api/petstore-server.gen.go @@ -76,7 +76,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // FindPets operation middleware func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -107,12 +106,11 @@ func (siw *ServerInterfaceWrapper) FindPets(w http.ResponseWriter, r *http.Reque handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // AddPet operation middleware func (siw *ServerInterfaceWrapper) AddPet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.AddPet(w, r) @@ -122,12 +120,11 @@ func (siw *ServerInterfaceWrapper) AddPet(w http.ResponseWriter, r *http.Request handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // DeletePet operation middleware func (siw *ServerInterfaceWrapper) DeletePet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -148,12 +145,11 @@ func (siw *ServerInterfaceWrapper) DeletePet(w http.ResponseWriter, r *http.Requ handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // FindPetByID operation middleware func (siw *ServerInterfaceWrapper) FindPetByID(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -174,7 +170,7 @@ func (siw *ServerInterfaceWrapper) FindPetByID(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/issues/issue-1039/server.gen.go b/internal/test/issues/issue-1039/server.gen.go index ac0e22b78e..a39f95dae7 100644 --- a/internal/test/issues/issue-1039/server.gen.go +++ b/internal/test/issues/issue-1039/server.gen.go @@ -37,7 +37,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // ExamplePatch operation middleware func (siw *ServerInterfaceWrapper) ExamplePatch(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.ExamplePatch(w, r) @@ -47,7 +46,7 @@ func (siw *ServerInterfaceWrapper) ExamplePatch(w http.ResponseWriter, r *http.R handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/issues/issue-1087/api.gen.go b/internal/test/issues/issue-1087/api.gen.go index 99d00fd329..3c408cc8f9 100644 --- a/internal/test/issues/issue-1087/api.gen.go +++ b/internal/test/issues/issue-1087/api.gen.go @@ -319,7 +319,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetThings operation middleware func (siw *ServerInterfaceWrapper) GetThings(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.GetThings(w, r) @@ -329,7 +328,7 @@ func (siw *ServerInterfaceWrapper) GetThings(w http.ResponseWriter, r *http.Requ handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/issues/issue-1378/bionicle/bionicle.gen.go b/internal/test/issues/issue-1378/bionicle/bionicle.gen.go index ec4c1f3b75..9f6ffc8809 100644 --- a/internal/test/issues/issue-1378/bionicle/bionicle.gen.go +++ b/internal/test/issues/issue-1378/bionicle/bionicle.gen.go @@ -48,7 +48,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetBionicleName operation middleware func (siw *ServerInterfaceWrapper) GetBionicleName(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -69,7 +68,7 @@ func (siw *ServerInterfaceWrapper) GetBionicleName(w http.ResponseWriter, r *htt handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/issues/issue-1378/fooservice/fooservice.gen.go b/internal/test/issues/issue-1378/fooservice/fooservice.gen.go index c74056ac5e..c11ca98979 100644 --- a/internal/test/issues/issue-1378/fooservice/fooservice.gen.go +++ b/internal/test/issues/issue-1378/fooservice/fooservice.gen.go @@ -41,7 +41,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetBionicleName operation middleware func (siw *ServerInterfaceWrapper) GetBionicleName(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -62,7 +61,7 @@ func (siw *ServerInterfaceWrapper) GetBionicleName(w http.ResponseWriter, r *htt handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/issues/issue-removed-external-ref/gen/spec_base/issue.gen.go b/internal/test/issues/issue-removed-external-ref/gen/spec_base/issue.gen.go index 627abde1f6..1a1c761002 100644 --- a/internal/test/issues/issue-removed-external-ref/gen/spec_base/issue.gen.go +++ b/internal/test/issues/issue-removed-external-ref/gen/spec_base/issue.gen.go @@ -59,7 +59,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // PostInvalidExtRefTrouble operation middleware func (siw *ServerInterfaceWrapper) PostInvalidExtRefTrouble(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.PostInvalidExtRefTrouble(w, r) @@ -69,12 +68,11 @@ func (siw *ServerInterfaceWrapper) PostInvalidExtRefTrouble(w http.ResponseWrite handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // PostNoTrouble operation middleware func (siw *ServerInterfaceWrapper) PostNoTrouble(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.PostNoTrouble(w, r) @@ -84,7 +82,7 @@ func (siw *ServerInterfaceWrapper) PostNoTrouble(w http.ResponseWriter, r *http. handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/name_normalizer.gen.go b/internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/name_normalizer.gen.go index 8c8853d6f6..d2a11387d0 100644 --- a/internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/name_normalizer.gen.go +++ b/internal/test/outputoptions/name-normalizer/to-camel-case-with-digits/name_normalizer.gen.go @@ -362,7 +362,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetHttpPet operation middleware func (siw *ServerInterfaceWrapper) GetHttpPet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -383,7 +382,7 @@ func (siw *ServerInterfaceWrapper) GetHttpPet(w http.ResponseWriter, r *http.Req handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/outputoptions/name-normalizer/to-camel-case-with-initialisms/name_normalizer.gen.go b/internal/test/outputoptions/name-normalizer/to-camel-case-with-initialisms/name_normalizer.gen.go index fc1286b8ae..3b2a1fa751 100644 --- a/internal/test/outputoptions/name-normalizer/to-camel-case-with-initialisms/name_normalizer.gen.go +++ b/internal/test/outputoptions/name-normalizer/to-camel-case-with-initialisms/name_normalizer.gen.go @@ -362,7 +362,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetHTTPPet operation middleware func (siw *ServerInterfaceWrapper) GetHTTPPet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -383,7 +382,7 @@ func (siw *ServerInterfaceWrapper) GetHTTPPet(w http.ResponseWriter, r *http.Req handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/outputoptions/name-normalizer/to-camel-case/name_normalizer.gen.go b/internal/test/outputoptions/name-normalizer/to-camel-case/name_normalizer.gen.go index 449d9e45e7..3e4ff389e2 100644 --- a/internal/test/outputoptions/name-normalizer/to-camel-case/name_normalizer.gen.go +++ b/internal/test/outputoptions/name-normalizer/to-camel-case/name_normalizer.gen.go @@ -362,7 +362,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetHttpPet operation middleware func (siw *ServerInterfaceWrapper) GetHttpPet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -383,7 +382,7 @@ func (siw *ServerInterfaceWrapper) GetHttpPet(w http.ResponseWriter, r *http.Req handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/outputoptions/name-normalizer/unset/name_normalizer.gen.go b/internal/test/outputoptions/name-normalizer/unset/name_normalizer.gen.go index ac6f4c8962..a2ef05ae8b 100644 --- a/internal/test/outputoptions/name-normalizer/unset/name_normalizer.gen.go +++ b/internal/test/outputoptions/name-normalizer/unset/name_normalizer.gen.go @@ -362,7 +362,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetHttpPet operation middleware func (siw *ServerInterfaceWrapper) GetHttpPet(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -383,7 +382,7 @@ func (siw *ServerInterfaceWrapper) GetHttpPet(w http.ResponseWriter, r *http.Req handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/server/server.gen.go b/internal/test/server/server.gen.go index cfc75b65c9..e360916b3a 100644 --- a/internal/test/server/server.gen.go +++ b/internal/test/server/server.gen.go @@ -238,7 +238,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // GetEveryTypeOptional operation middleware func (siw *ServerInterfaceWrapper) GetEveryTypeOptional(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.GetEveryTypeOptional(w, r) @@ -248,12 +247,11 @@ func (siw *ServerInterfaceWrapper) GetEveryTypeOptional(w http.ResponseWriter, r handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // GetSimple operation middleware func (siw *ServerInterfaceWrapper) GetSimple(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.GetSimple(w, r) @@ -263,12 +261,11 @@ func (siw *ServerInterfaceWrapper) GetSimple(w http.ResponseWriter, r *http.Requ handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // GetWithArgs operation middleware func (siw *ServerInterfaceWrapper) GetWithArgs(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -327,12 +324,11 @@ func (siw *ServerInterfaceWrapper) GetWithArgs(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // GetWithReferences operation middleware func (siw *ServerInterfaceWrapper) GetWithReferences(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -362,12 +358,11 @@ func (siw *ServerInterfaceWrapper) GetWithReferences(w http.ResponseWriter, r *h handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // GetWithContentType operation middleware func (siw *ServerInterfaceWrapper) GetWithContentType(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -388,12 +383,11 @@ func (siw *ServerInterfaceWrapper) GetWithContentType(w http.ResponseWriter, r * handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // GetReservedKeyword operation middleware func (siw *ServerInterfaceWrapper) GetReservedKeyword(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.GetReservedKeyword(w, r) @@ -403,12 +397,11 @@ func (siw *ServerInterfaceWrapper) GetReservedKeyword(w http.ResponseWriter, r * handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // CreateResource operation middleware func (siw *ServerInterfaceWrapper) CreateResource(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -429,12 +422,11 @@ func (siw *ServerInterfaceWrapper) CreateResource(w http.ResponseWriter, r *http handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // CreateResource2 operation middleware func (siw *ServerInterfaceWrapper) CreateResource2(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -466,12 +458,11 @@ func (siw *ServerInterfaceWrapper) CreateResource2(w http.ResponseWriter, r *htt handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UpdateResource3 operation middleware func (siw *ServerInterfaceWrapper) UpdateResource3(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -492,12 +483,11 @@ func (siw *ServerInterfaceWrapper) UpdateResource3(w http.ResponseWriter, r *htt handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // GetResponseWithReference operation middleware func (siw *ServerInterfaceWrapper) GetResponseWithReference(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.GetResponseWithReference(w, r) @@ -507,7 +497,7 @@ func (siw *ServerInterfaceWrapper) GetResponseWithReference(w http.ResponseWrite handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/strict-server/chi/server.gen.go b/internal/test/strict-server/chi/server.gen.go index 5725eb145f..c8c7a09245 100644 --- a/internal/test/strict-server/chi/server.gen.go +++ b/internal/test/strict-server/chi/server.gen.go @@ -139,7 +139,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // JSONExample operation middleware func (siw *ServerInterfaceWrapper) JSONExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.JSONExample(w, r) @@ -149,12 +148,11 @@ func (siw *ServerInterfaceWrapper) JSONExample(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // MultipartExample operation middleware func (siw *ServerInterfaceWrapper) MultipartExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.MultipartExample(w, r) @@ -164,12 +162,11 @@ func (siw *ServerInterfaceWrapper) MultipartExample(w http.ResponseWriter, r *ht handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // MultipartRelatedExample operation middleware func (siw *ServerInterfaceWrapper) MultipartRelatedExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.MultipartRelatedExample(w, r) @@ -179,12 +176,11 @@ func (siw *ServerInterfaceWrapper) MultipartRelatedExample(w http.ResponseWriter handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // MultipleRequestAndResponseTypes operation middleware func (siw *ServerInterfaceWrapper) MultipleRequestAndResponseTypes(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.MultipleRequestAndResponseTypes(w, r) @@ -194,12 +190,11 @@ func (siw *ServerInterfaceWrapper) MultipleRequestAndResponseTypes(w http.Respon handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // ReservedGoKeywordParameters operation middleware func (siw *ServerInterfaceWrapper) ReservedGoKeywordParameters(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -220,12 +215,11 @@ func (siw *ServerInterfaceWrapper) ReservedGoKeywordParameters(w http.ResponseWr handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // ReusableResponses operation middleware func (siw *ServerInterfaceWrapper) ReusableResponses(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.ReusableResponses(w, r) @@ -235,12 +229,11 @@ func (siw *ServerInterfaceWrapper) ReusableResponses(w http.ResponseWriter, r *h handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // TextExample operation middleware func (siw *ServerInterfaceWrapper) TextExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.TextExample(w, r) @@ -250,12 +243,11 @@ func (siw *ServerInterfaceWrapper) TextExample(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UnknownExample operation middleware func (siw *ServerInterfaceWrapper) UnknownExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.UnknownExample(w, r) @@ -265,12 +257,11 @@ func (siw *ServerInterfaceWrapper) UnknownExample(w http.ResponseWriter, r *http handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UnspecifiedContentType operation middleware func (siw *ServerInterfaceWrapper) UnspecifiedContentType(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.UnspecifiedContentType(w, r) @@ -280,12 +271,11 @@ func (siw *ServerInterfaceWrapper) UnspecifiedContentType(w http.ResponseWriter, handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // URLEncodedExample operation middleware func (siw *ServerInterfaceWrapper) URLEncodedExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.URLEncodedExample(w, r) @@ -295,12 +285,11 @@ func (siw *ServerInterfaceWrapper) URLEncodedExample(w http.ResponseWriter, r *h handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // HeadersExample operation middleware func (siw *ServerInterfaceWrapper) HeadersExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -359,12 +348,11 @@ func (siw *ServerInterfaceWrapper) HeadersExample(w http.ResponseWriter, r *http handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UnionExample operation middleware func (siw *ServerInterfaceWrapper) UnionExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.UnionExample(w, r) @@ -374,7 +362,7 @@ func (siw *ServerInterfaceWrapper) UnionExample(w http.ResponseWriter, r *http.R handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/strict-server/gorilla/server.gen.go b/internal/test/strict-server/gorilla/server.gen.go index 07612e98ff..c6b29393df 100644 --- a/internal/test/strict-server/gorilla/server.gen.go +++ b/internal/test/strict-server/gorilla/server.gen.go @@ -75,7 +75,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // JSONExample operation middleware func (siw *ServerInterfaceWrapper) JSONExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.JSONExample(w, r) @@ -85,12 +84,11 @@ func (siw *ServerInterfaceWrapper) JSONExample(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // MultipartExample operation middleware func (siw *ServerInterfaceWrapper) MultipartExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.MultipartExample(w, r) @@ -100,12 +98,11 @@ func (siw *ServerInterfaceWrapper) MultipartExample(w http.ResponseWriter, r *ht handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // MultipartRelatedExample operation middleware func (siw *ServerInterfaceWrapper) MultipartRelatedExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.MultipartRelatedExample(w, r) @@ -115,12 +112,11 @@ func (siw *ServerInterfaceWrapper) MultipartRelatedExample(w http.ResponseWriter handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // MultipleRequestAndResponseTypes operation middleware func (siw *ServerInterfaceWrapper) MultipleRequestAndResponseTypes(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.MultipleRequestAndResponseTypes(w, r) @@ -130,12 +126,11 @@ func (siw *ServerInterfaceWrapper) MultipleRequestAndResponseTypes(w http.Respon handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // ReservedGoKeywordParameters operation middleware func (siw *ServerInterfaceWrapper) ReservedGoKeywordParameters(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -156,12 +151,11 @@ func (siw *ServerInterfaceWrapper) ReservedGoKeywordParameters(w http.ResponseWr handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // ReusableResponses operation middleware func (siw *ServerInterfaceWrapper) ReusableResponses(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.ReusableResponses(w, r) @@ -171,12 +165,11 @@ func (siw *ServerInterfaceWrapper) ReusableResponses(w http.ResponseWriter, r *h handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // TextExample operation middleware func (siw *ServerInterfaceWrapper) TextExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.TextExample(w, r) @@ -186,12 +179,11 @@ func (siw *ServerInterfaceWrapper) TextExample(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UnknownExample operation middleware func (siw *ServerInterfaceWrapper) UnknownExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.UnknownExample(w, r) @@ -201,12 +193,11 @@ func (siw *ServerInterfaceWrapper) UnknownExample(w http.ResponseWriter, r *http handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UnspecifiedContentType operation middleware func (siw *ServerInterfaceWrapper) UnspecifiedContentType(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.UnspecifiedContentType(w, r) @@ -216,12 +207,11 @@ func (siw *ServerInterfaceWrapper) UnspecifiedContentType(w http.ResponseWriter, handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // URLEncodedExample operation middleware func (siw *ServerInterfaceWrapper) URLEncodedExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.URLEncodedExample(w, r) @@ -231,12 +221,11 @@ func (siw *ServerInterfaceWrapper) URLEncodedExample(w http.ResponseWriter, r *h handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // HeadersExample operation middleware func (siw *ServerInterfaceWrapper) HeadersExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -295,12 +284,11 @@ func (siw *ServerInterfaceWrapper) HeadersExample(w http.ResponseWriter, r *http handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UnionExample operation middleware func (siw *ServerInterfaceWrapper) UnionExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.UnionExample(w, r) @@ -310,7 +298,7 @@ func (siw *ServerInterfaceWrapper) UnionExample(w http.ResponseWriter, r *http.R handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/internal/test/strict-server/stdhttp/server.gen.go b/internal/test/strict-server/stdhttp/server.gen.go index 57140ea31f..6a3b2537a9 100644 --- a/internal/test/strict-server/stdhttp/server.gen.go +++ b/internal/test/strict-server/stdhttp/server.gen.go @@ -76,7 +76,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // JSONExample operation middleware func (siw *ServerInterfaceWrapper) JSONExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.JSONExample(w, r) @@ -86,12 +85,11 @@ func (siw *ServerInterfaceWrapper) JSONExample(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // MultipartExample operation middleware func (siw *ServerInterfaceWrapper) MultipartExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.MultipartExample(w, r) @@ -101,12 +99,11 @@ func (siw *ServerInterfaceWrapper) MultipartExample(w http.ResponseWriter, r *ht handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // MultipartRelatedExample operation middleware func (siw *ServerInterfaceWrapper) MultipartRelatedExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.MultipartRelatedExample(w, r) @@ -116,12 +113,11 @@ func (siw *ServerInterfaceWrapper) MultipartRelatedExample(w http.ResponseWriter handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // MultipleRequestAndResponseTypes operation middleware func (siw *ServerInterfaceWrapper) MultipleRequestAndResponseTypes(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.MultipleRequestAndResponseTypes(w, r) @@ -131,12 +127,11 @@ func (siw *ServerInterfaceWrapper) MultipleRequestAndResponseTypes(w http.Respon handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // ReservedGoKeywordParameters operation middleware func (siw *ServerInterfaceWrapper) ReservedGoKeywordParameters(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -157,12 +152,11 @@ func (siw *ServerInterfaceWrapper) ReservedGoKeywordParameters(w http.ResponseWr handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // ReusableResponses operation middleware func (siw *ServerInterfaceWrapper) ReusableResponses(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.ReusableResponses(w, r) @@ -172,12 +166,11 @@ func (siw *ServerInterfaceWrapper) ReusableResponses(w http.ResponseWriter, r *h handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // TextExample operation middleware func (siw *ServerInterfaceWrapper) TextExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.TextExample(w, r) @@ -187,12 +180,11 @@ func (siw *ServerInterfaceWrapper) TextExample(w http.ResponseWriter, r *http.Re handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UnknownExample operation middleware func (siw *ServerInterfaceWrapper) UnknownExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.UnknownExample(w, r) @@ -202,12 +194,11 @@ func (siw *ServerInterfaceWrapper) UnknownExample(w http.ResponseWriter, r *http handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UnspecifiedContentType operation middleware func (siw *ServerInterfaceWrapper) UnspecifiedContentType(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.UnspecifiedContentType(w, r) @@ -217,12 +208,11 @@ func (siw *ServerInterfaceWrapper) UnspecifiedContentType(w http.ResponseWriter, handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // URLEncodedExample operation middleware func (siw *ServerInterfaceWrapper) URLEncodedExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.URLEncodedExample(w, r) @@ -232,12 +222,11 @@ func (siw *ServerInterfaceWrapper) URLEncodedExample(w http.ResponseWriter, r *h handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // HeadersExample operation middleware func (siw *ServerInterfaceWrapper) HeadersExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() var err error @@ -296,12 +285,11 @@ func (siw *ServerInterfaceWrapper) HeadersExample(w http.ResponseWriter, r *http handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } // UnionExample operation middleware func (siw *ServerInterfaceWrapper) UnionExample(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { siw.Handler.UnionExample(w, r) @@ -311,7 +299,7 @@ func (siw *ServerInterfaceWrapper) UnionExample(w http.ResponseWriter, r *http.R handler = middleware(handler) } - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } type UnescapedCookieParamError struct { diff --git a/pkg/codegen/templates/chi/chi-middleware.tmpl b/pkg/codegen/templates/chi/chi-middleware.tmpl index 2e84418f92..ced82b4c42 100644 --- a/pkg/codegen/templates/chi/chi-middleware.tmpl +++ b/pkg/codegen/templates/chi/chi-middleware.tmpl @@ -11,7 +11,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // {{$opid}} operation middleware func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() {{if or .RequiresParamObject (gt (len .PathParams) 0) }} var err error {{end}} @@ -39,9 +38,13 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ {{end}} + {{if .SecurityDefinitions -}} + ctx := r.Context() {{range .SecurityDefinitions}} ctx = context.WithValue(ctx, {{.ProviderName | sanitizeGoIdentity | ucFirst}}Scopes, {{toStringArray .Scopes}}) {{end}} + r = r.WithContext(ctx) + {{end}} {{if .RequiresParamObject}} // Parameter object where we will unmarshal all parameters from the context @@ -187,7 +190,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ } {{end}} - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } {{end}} diff --git a/pkg/codegen/templates/gorilla/gorilla-middleware.tmpl b/pkg/codegen/templates/gorilla/gorilla-middleware.tmpl index 9b4068790c..4353c9f42f 100644 --- a/pkg/codegen/templates/gorilla/gorilla-middleware.tmpl +++ b/pkg/codegen/templates/gorilla/gorilla-middleware.tmpl @@ -11,7 +11,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // {{$opid}} operation middleware func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() {{if or .RequiresParamObject (gt (len .PathParams) 0) }} var err error {{end}} @@ -39,9 +38,13 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ {{end}} + {{if .SecurityDefinitions -}} + ctx := r.Context() {{range .SecurityDefinitions}} ctx = context.WithValue(ctx, {{.ProviderName | sanitizeGoIdentity | ucFirst}}Scopes, {{toStringArray .Scopes}}) {{end}} + r = r.WithContext(ctx) + {{end}} {{if .RequiresParamObject}} // Parameter object where we will unmarshal all parameters from the context @@ -187,7 +190,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ } {{end}} - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } {{end}} diff --git a/pkg/codegen/templates/stdhttp/std-http-middleware.tmpl b/pkg/codegen/templates/stdhttp/std-http-middleware.tmpl index 8ef7187a20..02805ef175 100644 --- a/pkg/codegen/templates/stdhttp/std-http-middleware.tmpl +++ b/pkg/codegen/templates/stdhttp/std-http-middleware.tmpl @@ -11,7 +11,6 @@ type MiddlewareFunc func(http.Handler) http.Handler // {{$opid}} operation middleware func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() {{if or .RequiresParamObject (gt (len .PathParams) 0) }} var err error {{end}} @@ -39,9 +38,13 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ {{end}} + {{if .SecurityDefinitions -}} + ctx := r.Context() {{range .SecurityDefinitions}} ctx = context.WithValue(ctx, {{.ProviderName | sanitizeGoIdentity | ucFirst}}Scopes, {{toStringArray .Scopes}}) {{end}} + r = r.WithContext(ctx) + {{end}} {{if .RequiresParamObject}} // Parameter object where we will unmarshal all parameters from the context @@ -187,7 +190,7 @@ func (siw *ServerInterfaceWrapper) {{$opid}}(w http.ResponseWriter, r *http.Requ } {{end}} - handler.ServeHTTP(w, r.WithContext(ctx)) + handler.ServeHTTP(w, r) } {{end}}