From d556b3b579cd801b9765f75199c19cb64216f6c8 Mon Sep 17 00:00:00 2001 From: EwenQuim Date: Sun, 22 Dec 2024 13:09:27 +0100 Subject: [PATCH] Moves route.Hidden check to RegisterOpenAPIOperation --- mux.go | 4 ---- openapi.go | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mux.go b/mux.go index e5dfa929..2cff9bf3 100644 --- a/mux.go +++ b/mux.go @@ -86,10 +86,6 @@ func Register[T, B any](s *Server, route Route[T, B], controller http.Handler, o route.Middlewares = append(s.middlewares, route.Middlewares...) s.Mux.Handle(fullPath, withMiddlewares(route.Handler, route.Middlewares...)) - if route.Hidden || route.Method == "" { - return &route - } - err := route.RegisterOpenAPIOperation(s.OpenAPI) if err != nil { slog.Warn("error documenting openapi operation", "error", err) diff --git a/openapi.go b/openapi.go index a30ce75a..8f3a0839 100644 --- a/openapi.go +++ b/openapi.go @@ -208,6 +208,10 @@ func validateSwaggerUrl(swaggerUrl string) bool { // RegisterOpenAPIOperation registers the route to the OpenAPI description. // Modifies the route's Operation. func (route *Route[ResponseBody, RequestBody]) RegisterOpenAPIOperation(openapi *OpenAPI) error { + if route.Hidden || route.Method == "" { + return nil + } + operation, err := RegisterOpenAPIOperation(openapi, *route) route.Operation = operation return err