Skip to content

Commit bf6a37b

Browse files
its-hammer-timecursoragent
authored andcommitted
Address review feedback: DisablePathTree, copyright years
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent d6c31a0 commit bf6a37b

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

config/config.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type ValidationOptions struct {
3232
Formats map[string]func(v any) error
3333
SchemaCache cache.SchemaCache // Optional cache for compiled schemas
3434
PathTree radix.PathLookup // O(k) path lookup via radix tree (built automatically)
35-
pathTreeSet bool // Internal: true if PathTree was explicitly set via WithPathTree
35+
pathTreeDisabled bool // Internal: true if radix tree auto-build was disabled via DisablePathTree
3636
Logger *slog.Logger // Logger for debug/error output (nil = silent)
3737
AllowXMLBodyValidation bool // Allows to convert XML to JSON for validating a request/response body.
3838
AllowURLEncodedBodyValidation bool // Allows to convert URL Encoded to JSON for validating a request/response body.
@@ -80,7 +80,7 @@ func WithExistingOpts(options *ValidationOptions) Option {
8080
o.Formats = options.Formats
8181
o.SchemaCache = options.SchemaCache
8282
o.PathTree = options.PathTree
83-
o.pathTreeSet = options.pathTreeSet
83+
o.pathTreeDisabled = options.pathTreeDisabled
8484
o.Logger = options.Logger
8585
o.AllowXMLBodyValidation = options.AllowXMLBodyValidation
8686
o.AllowURLEncodedBodyValidation = options.AllowURLEncodedBodyValidation
@@ -197,11 +197,17 @@ func WithSchemaCache(schemaCache cache.SchemaCache) Option {
197197

198198
// WithPathTree sets a custom radix tree for path matching.
199199
// The default is built automatically from the OpenAPI specification.
200-
// Pass nil to disable the radix tree and use regex-based matching only.
201200
func WithPathTree(pathTree radix.PathLookup) Option {
202201
return func(o *ValidationOptions) {
203202
o.PathTree = pathTree
204-
o.pathTreeSet = true
203+
}
204+
}
205+
206+
// DisablePathTree prevents automatic radix tree construction.
207+
// Use this to fall back to regex-based path matching only.
208+
func DisablePathTree() Option {
209+
return func(o *ValidationOptions) {
210+
o.pathTreeDisabled = true
205211
}
206212
}
207213

@@ -268,9 +274,9 @@ var defaultIgnoredHeaders = []string{
268274
"request-start-time", // Added by some API clients for timing
269275
}
270276

271-
// IsPathTreeSet returns true if PathTree was explicitly configured via WithPathTree.
272-
func (o *ValidationOptions) IsPathTreeSet() bool {
273-
return o.pathTreeSet
277+
// IsPathTreeDisabled returns true if radix tree auto-build was disabled via DisablePathTree.
278+
func (o *ValidationOptions) IsPathTreeDisabled() bool {
279+
return o.pathTreeDisabled
274280
}
275281

276282
// GetEffectiveStrictIgnoredHeaders returns the list of headers to ignore

radix/path_tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley
1+
// Copyright 2026 Princess B33f Heavy Industries / Dave Shanley
22
// SPDX-License-Identifier: MIT
33

44
package radix

radix/tree.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley
1+
// Copyright 2026 Princess B33f Heavy Industries / Dave Shanley
22
// SPDX-License-Identifier: MIT
33

44
// Package radix provides a radix tree (prefix tree) implementation optimized for

validator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ func NewValidatorFromV3Model(m *v3.Document, opts ...config.Option) Validator {
9090
options := config.NewValidationOptions(opts...)
9191

9292
// Build radix tree for O(k) path lookup (where k = path depth)
93-
// Skip if explicitly set via WithPathTree (including nil to disable)
94-
if options.PathTree == nil && !options.IsPathTreeSet() {
93+
// Skip if path tree is disabled or a custom tree was provided
94+
if options.PathTree == nil && !options.IsPathTreeDisabled() {
9595
options.PathTree = radix.BuildPathTree(m)
9696
}
9797

0 commit comments

Comments
 (0)