Skip to content

Commit

Permalink
perf: disable route registration when Engine.OpenAPIConfig.Disabled i…
Browse files Browse the repository at this point in the history
…s set to true
  • Loading branch information
dylanhitt committed Dec 29, 2024
1 parent 12d3b26 commit 5c02854
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions generic_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type Registerer[T, B any] interface {
func Registers[B, T any](engine *Engine, a Registerer[B, T]) *Route[B, T] {
route := a.Register()

if engine.OpenAPIConfig.Disabled {
return &route
}
err := route.RegisterOpenAPIOperation(engine.OpenAPI)
if err != nil {
slog.Warn("error documenting openapi operation", "error", err)
Expand Down
6 changes: 3 additions & 3 deletions openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func TestServer_OutputOpenApiSpec(t *testing.T) {
require.Error(t, err)
require.Nil(t, file)
})
t.Run("swagger disabled", func(t *testing.T) {
t.Run("OpenAPI disabled", func(t *testing.T) {
s := NewServer(
WithEngineOptions(
WithOpenAPIConfig(
Expand All @@ -303,7 +303,7 @@ func TestServer_OutputOpenApiSpec(t *testing.T) {
})

document := s.OutputOpenAPISpec()
require.Len(t, document.Paths.Map(), 1)
require.Empty(t, document.Paths.Map())
require.NotNil(t, document)

file, err := os.Open(docPath)
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestAutoGroupTags(t *testing.T) {
WithEngineOptions(
WithOpenAPIConfig(OpenAPIConfig{
DisableLocalSave: true,
Disabled: true,
Disabled: false,
}),
),
)
Expand Down

0 comments on commit 5c02854

Please sign in to comment.