Skip to content

Commit

Permalink
Generate description is in OpenAPI registration, not in mux registration
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Dec 14, 2024
1 parent 786d3bf commit 5355ebc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
12 changes: 4 additions & 8 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ type BaseRoute struct {
overrideDescription bool // Override the default description
}

func (r *BaseRoute) GenerateDefaultDescription(otherMiddlewares ...func(http.Handler) http.Handler) {
func (r *BaseRoute) GenerateDefaultDescription() {
if r.overrideDescription {
return
}
r.Operation.Description = DefaultDescription(r.FullName, append(r.Middlewares, otherMiddlewares...)) + r.Operation.Description
r.Operation.Description = DefaultDescription(r.FullName, r.Middlewares) + r.Operation.Description
}

func (r *BaseRoute) GenerateDefaultOperationID() {
Expand Down Expand Up @@ -114,8 +114,8 @@ func Register[T, B any](s *Server, route Route[T, B], controller http.Handler, o
}
slog.Debug("registering controller " + fullPath)

allMiddlewares := append(s.middlewares, route.Middlewares...)
s.Mux.Handle(fullPath, withMiddlewares(route.Handler, allMiddlewares...))
route.Middlewares = append(s.middlewares, route.Middlewares...)
s.Mux.Handle(fullPath, withMiddlewares(route.Handler, route.Middlewares...))

if s.DisableOpenapi || route.Hidden || route.Method == "" {
return &route
Expand Down Expand Up @@ -190,8 +190,6 @@ func registerFuegoController[T, B any, Contexted ctx[B]](s *Server, method, path
o(&route)
}

route.GenerateDefaultDescription(s.middlewares...)

return Register(s, Route[T, B]{BaseRoute: route}, HTTPHandler(s, controller, &route))
}

Expand All @@ -210,8 +208,6 @@ func registerStdController(s *Server, method, path string, controller func(http.
o(&route)
}

route.GenerateDefaultDescription(s.middlewares...)

return Register(s, Route[any, any]{BaseRoute: route}, http.HandlerFunc(controller))
}

Expand Down
2 changes: 1 addition & 1 deletion mux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func TestRegister(t *testing.T) {
}, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}),
OptionOperationID("new-operation-id"),
OptionSummary("new-summary"),
OptionDescription("new-description"),
OptionOverrideDescription("new-description"),
OptionTags("new-tag"),
)

Expand Down
2 changes: 2 additions & 0 deletions openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ func RegisterOpenAPIOperation[T, B any](openapi *OpenAPI, route Route[T, B]) (*o
route.FullName = route.Path
}

route.GenerateDefaultDescription()

if route.Operation.Summary == "" {
route.Operation.Summary = route.NameFromNamespace(camelToHuman)
}
Expand Down

0 comments on commit 5355ebc

Please sign in to comment.