Skip to content

Commit c484506

Browse files
committed
feat: add OptionShow
1 parent 6a7c0cb commit c484506

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

mux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func Register[T, B any](s *Server, route Route[T, B], controller http.Handler, o
8686
route.Middlewares = append(s.middlewares, route.Middlewares...)
8787
s.Mux.Handle(fullPath, withMiddlewares(route.Handler, route.Middlewares...))
8888

89-
if s.DisableOpenapi || route.Hidden || route.Method == "" {
89+
if route.Hidden || route.Method == "" {
9090
return &route
9191
}
9292

mux_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,6 @@ func TestHideOpenapiRoutes(t *testing.T) {
487487
s.Hide()
488488
Get(s, "/test", func(ctx ContextNoBody) (string, error) { return "", nil })
489489

490-
require.Equal(t, s.DisableOpenapi, true)
491490
require.True(t, s.OpenAPI.Description().Paths.Find("/not-hidden") != nil)
492491
require.True(t, s.OpenAPI.Description().Paths.Find("/test") == nil)
493492
})
@@ -499,7 +498,6 @@ func TestHideOpenapiRoutes(t *testing.T) {
499498
g := Group(s, "/group").Hide()
500499
Get(g, "/test", func(ctx ContextNoBody) (string, error) { return "", nil })
501500

502-
require.Equal(t, g.DisableOpenapi, true)
503501
require.True(t, s.OpenAPI.Description().Paths.Find("/not-hidden") != nil)
504502
require.True(t, s.OpenAPI.Description().Paths.Find("/group/test") == nil)
505503
})
@@ -512,8 +510,6 @@ func TestHideOpenapiRoutes(t *testing.T) {
512510
g2 := Group(s, "/group2")
513511
Get(g2, "/test", func(ctx ContextNoBody) (string, error) { return "test", nil })
514512

515-
require.Equal(t, true, g.DisableOpenapi)
516-
require.Equal(t, false, g2.DisableOpenapi)
517513
require.True(t, s.OpenAPI.Description().Paths.Find("/group/test") == nil)
518514
require.True(t, s.OpenAPI.Description().Paths.Find("/group2/test") != nil)
519515
})
@@ -526,7 +522,6 @@ func TestHideOpenapiRoutes(t *testing.T) {
526522
g2 := Group(g, "/sub").Show()
527523
Get(g2, "/test", func(ctx ContextNoBody) (string, error) { return "test", nil })
528524

529-
require.Equal(t, true, g.DisableOpenapi)
530525
require.True(t, s.OpenAPI.Description().Paths.Find("/group/test") == nil)
531526
require.True(t, s.OpenAPI.Description().Paths.Find("/group/sub/test") != nil)
532527
})

openapi.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,21 @@ func NewOpenApiSpec() openapi3.T {
8585
}
8686

8787
// Hide prevents the routes in this server or group from being included in the OpenAPI spec.
88+
// Deprecated: Please use [OptionHide] with [WithRouteOptions]
8889
func (s *Server) Hide() *Server {
89-
s.DisableOpenapi = true
90+
WithRouteOptions(
91+
OptionHide(),
92+
)(s)
9093
return s
9194
}
9295

9396
// Show allows displaying the routes. Activated by default so useless in most cases,
9497
// but this can be useful if you deactivated the parent group.
98+
// Deprecated: Please use [OptionShow] with [WithRouteOptions]
9599
func (s *Server) Show() *Server {
96-
s.DisableOpenapi = false
100+
WithRouteOptions(
101+
OptionShow(),
102+
)(s)
97103
return s
98104
}
99105

option.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,13 @@ func OptionHide() func(*BaseRoute) {
371371
}
372372
}
373373

374+
// Show shows the route from the OpenAPI spec.
375+
func OptionShow() func(*BaseRoute) {
376+
return func(r *BaseRoute) {
377+
r.Hidden = false
378+
}
379+
}
380+
374381
// OptionDefaultStatusCode sets the default status code for the route.
375382
func OptionDefaultStatusCode(defaultStatusCode int) func(*BaseRoute) {
376383
return func(r *BaseRoute) {
@@ -431,3 +438,9 @@ func OptionSecurity(securityRequirements ...openapi3.SecurityRequirement) func(*
431438
*r.Operation.Security = append(*r.Operation.Security, securityRequirements...)
432439
}
433440
}
441+
442+
func OptionShowInOpenAPI(show bool) func(*BaseRoute) {
443+
return func(r *BaseRoute) {
444+
445+
}
446+
}

option/option.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,8 @@ var RequestContentType = fuego.OptionRequestContentType
170170
// Hide hides the route from the OpenAPI spec.
171171
var Hide = fuego.OptionHide
172172

173+
// Hide hides the route from the OpenAPI spec.
174+
var Show = fuego.OptionShow
175+
173176
// DefaultStatusCode sets the default status code for the route.
174177
var DefaultStatusCode = fuego.OptionDefaultStatusCode

server.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,10 @@ type Server struct {
6464
fs fs.FS
6565
template *template.Template // TODO: use preparsed templates
6666

67-
DisallowUnknownFields bool // If true, the server will return an error if the request body contains unknown fields. Useful for quick debugging in development.
68-
DisableOpenapi bool // If true, the routes within the server will not generate an OpenAPI spec.
67+
acceptedContentTypes []string
68+
69+
// If true, the server will return an error if the request body contains unknown fields. Useful for quick debugging in development.
70+
DisallowUnknownFields bool
6971
maxBodySize int64
7072

7173
// Custom serializer that overrides the default one.

0 commit comments

Comments
 (0)