Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: move accept header form mux to server options #324

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions net_http_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"runtime"
"strings"

"github.com/getkin/kin-openapi/openapi3"

Check failure on line 10 in net_http_mux.go

View workflow job for this annotation

GitHub Actions / golangci-lint

"github.com/getkin/kin-openapi/openapi3" imported and not used (typecheck)

Check failure on line 10 in net_http_mux.go

View workflow job for this annotation

GitHub Actions / golangci-lint

"github.com/getkin/kin-openapi/openapi3" imported and not used) (typecheck)

Check failure on line 10 in net_http_mux.go

View workflow job for this annotation

GitHub Actions / golangci-lint

"github.com/getkin/kin-openapi/openapi3" imported and not used) (typecheck)

Check failure on line 10 in net_http_mux.go

View workflow job for this annotation

GitHub Actions / golangci-lint

"github.com/getkin/kin-openapi/openapi3" imported and not used) (typecheck)

Check failure on line 10 in net_http_mux.go

View workflow job for this annotation

GitHub Actions / tests

"github.com/getkin/kin-openapi/openapi3" imported and not used

Check failure on line 10 in net_http_mux.go

View workflow job for this annotation

GitHub Actions / govulncheck

"github.com/getkin/kin-openapi/openapi3" imported and not used
)

// Group allows grouping routes under a common path.
Expand Down Expand Up @@ -137,10 +137,6 @@
func registerFuegoController[T, B any](s *Server, method, path string, controller func(ContextWithBody[B]) (T, error), options ...func(*BaseRoute)) *Route[T, B] {
route := NewRoute[T, B](method, path, controller, s.OpenAPI, append(s.routeOptions, options...)...)

acceptHeaderParameter := openapi3.NewHeaderParameter("Accept")
acceptHeaderParameter.Schema = openapi3.NewStringSchema().NewRef()
route.Operation.AddParameter(acceptHeaderParameter)

return Registers(s.Engine, netHttpRouteRegisterer[T, B]{
s: s,
route: route,
Expand Down Expand Up @@ -232,4 +228,4 @@

func (a netHttpRouteRegisterer[T, B]) Register() Route[T, B] {
return *Register(a.s, a.route, a.controller)
}
}
8 changes: 7 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ func NewServer(options ...func(*Server)) *Server {
WithRouteOptions(
OptionAddResponse(http.StatusBadRequest, "Bad Request _(validation or deserialization error)_", Response{Type: HTTPError{}}),
OptionAddResponse(http.StatusInternalServerError, "Internal Server Error _(panics)_", Response{Type: HTTPError{}}),

func(r *BaseRoute) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have an option OptionHeader that you can use !

acceptHeaderParameter := openapi3.NewHeaderParameter("Accept")
acceptHeaderParameter.Schema = openapi3.NewStringSchema().NewRef()
r.Operation.AddParameter(acceptHeaderParameter)
},
),
}
options = append(defaultOptions[:], options...)
Expand Down Expand Up @@ -441,4 +447,4 @@ func WithLoggingMiddleware(loggingConfig LoggingConfig) func(*Server) {
s.loggingConfig.RequestIDFunc = loggingConfig.RequestIDFunc
}
}
}
}
Loading