这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
19 changes: 10 additions & 9 deletions huma.go
Original file line number Diff line number Diff line change
Expand Up @@ -1334,17 +1334,18 @@ func Register[I, O any](api API, op Operation, handler func(context.Context, *I)
elem.Set(item)
item = ptr
}
if resolver, ok := item.Interface().(Resolver); ok {
if errs := resolver.Resolve(ctx); len(errs) > 0 {
res.Errors = append(res.Errors, errs...)
}
} else if resolver, ok := item.Interface().(ResolverWithPath); ok {
if errs := resolver.Resolve(ctx, pb); len(errs) > 0 {
res.Errors = append(res.Errors, errs...)
}
} else {
var errs []error
switch resolver := item.Interface().(type) {
case Resolver:
errs = resolver.Resolve(ctx)
case ResolverWithPath:
errs = resolver.Resolve(ctx, pb)
default:
panic("matched resolver cannot be run, please file a bug")
}
if len(errs) > 0 {
res.Errors = append(res.Errors, errs...)
}
})

if len(res.Errors) > 0 {
Expand Down
7 changes: 4 additions & 3 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,12 @@ func (s *Schema) PrecomputeMessages() {

func boolTag(f reflect.StructField, tag string, def bool) bool {
if v := f.Tag.Get(tag); v != "" {
if v == "true" {
switch v {
case "true":
return true
} else if v == "false" {
case "false":
return false
} else {
default:
panic(fmt.Errorf("invalid bool tag '%s' for field '%s': %v", tag, f.Name, v))
}
}
Expand Down
7 changes: 4 additions & 3 deletions validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,12 @@ func Validate(r Registry, s *Schema, path *PathBuffer, mode ValidateMode, v any,
return
}
case TypeObject:
if vv, ok := v.(map[string]any); ok {
switch vv := v.(type) {
case map[string]any:
handleMapString(r, s, path, mode, vv, res)
} else if vv, ok := v.(map[any]any); ok {
case map[any]any:
handleMapAny(r, s, path, mode, vv, res)
} else {
default:
res.Add(path, v, validation.MsgExpectedObject)
return
}
Expand Down
5 changes: 3 additions & 2 deletions validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,10 +1476,11 @@ func BenchmarkValidate(b *testing.B) {

input := test.input
if s.Type == huma.TypeObject && s.Properties["value"] != nil {
if i, ok := input.(map[string]any); ok {
switch i := input.(type) {
case map[string]any:
input = i["value"]
s = s.Properties["value"]
} else if i, ok := input.(map[any]any); ok {
case map[any]any:
input = i["value"]
s = s.Properties["value"]
}
Expand Down