Skip to content

Commit

Permalink
Removes hardcoded Accept header from registerFuegoController
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Jan 31, 2025
1 parent 0f9e5b4 commit 61053e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
7 changes: 1 addition & 6 deletions net_http_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"reflect"
"runtime"
"strings"

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

// Group allows grouping routes under a common path.
Expand Down Expand Up @@ -135,12 +133,9 @@ func PatchStd(s *Server, path string, controller func(http.ResponseWriter, *http
}

func registerFuegoController[T, B any](s *Server, method, path string, controller func(ContextWithBody[B]) (T, error), options ...func(*BaseRoute)) *Route[T, B] {
options = append(options, OptionHeader("Accept", ""))
route := NewRoute[T, B](method, path, controller, s.Engine, 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
3 changes: 2 additions & 1 deletion option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,10 @@ func TestGroup(t *testing.T) {

require.NotNil(t, route)
require.NotNil(t, route.Params)
require.Len(t, route.Params, 3)
require.Len(t, route.Params, 4)
require.Equal(t, "test header", route.Params["X-Test"].Description)
require.Equal(t, "My Header", route.Operation.Parameters.GetByInAndName("header", "X-Test").Examples["test"].Value.Value)
require.Equal(t, "Accept", route.Operation.Parameters.GetByInAndName("header", "Accept").Name)
})
}

Expand Down
7 changes: 6 additions & 1 deletion param_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestParams(t *testing.T) {

require.NotNil(t, route)
require.NotNil(t, route.Params)
require.Len(t, route.Params, 3)
require.Len(t, route.Params, 4)
require.Equal(t, "Name", route.Params["name"].Description)
require.True(t, route.Params["name"].Required)
require.Equal(t, "hey", route.Params["name"].Default)
Expand All @@ -39,5 +39,10 @@ func TestParams(t *testing.T) {
require.True(t, route.Params["age"].Nullable)
require.Equal(t, 18, route.Params["age"].Default)
require.Equal(t, "integer", route.Params["age"].GoType)

require.Equal(t, "Is OK?", route.Params["is_ok"].Description)
require.Equal(t, true, route.Params["is_ok"].Default)

require.Equal(t, "Accept", route.Params["Accept"].Name)
})
}

0 comments on commit 61053e2

Please sign in to comment.