MCPcopy
hub / github.com/danielgtaylor/huma / BenchmarkValidate

Function BenchmarkValidate

validate_test.go:1572–1616  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

1570var BenchValidateRes *huma.ValidateResult
1571
1572func BenchmarkValidate(b *testing.B) {
1573 pb := huma.NewPathBuffer([]byte(""), 0)
1574 res := &huma.ValidateResult{}
1575 BenchValidatePB = pb
1576 BenchValidateRes = res
1577
1578 for _, test := range validateTests {
1579 if test.panic != "" || len(test.errs) > 0 || test.typ == nil {
1580 continue
1581 }
1582
1583 b.Run(strings.TrimSuffix(test.name, " success"), func(b *testing.B) {
1584 registry := huma.NewMapRegistry("#/components/schemas/", huma.DefaultSchemaNamer)
1585 s := registry.Schema(test.typ, false, "TestInput")
1586
1587 input := test.input
1588 if s.Type == huma.TypeObject && s.Properties["value"] != nil {
1589 switch i := input.(type) {
1590 case map[string]any:
1591 for k := range i {
1592 if strings.EqualFold(k, "value") {
1593 input = i[k]
1594 }
1595 }
1596 s = s.Properties["value"]
1597 case map[any]any:
1598 for k := range i {
1599 if strings.EqualFold(fmt.Sprintf("%v", k), "value") {
1600 input = i[k]
1601 }
1602 }
1603 s = s.Properties["value"]
1604 }
1605 }
1606
1607 b.ReportAllocs()
1608 b.ResetTimer()
1609 for i := 0; i < b.N; i++ {
1610 pb.Reset()
1611 res.Reset()
1612 huma.Validate(registry, s, pb, test.mode, input, res)
1613 }
1614 })
1615 }
1616}
1617
1618type Cat struct {
1619 Name string `json:"name" minLength:"2" maxLength:"10"`

Callers

nothing calls this directly

Calls 5

ResetMethod · 0.95
ResetMethod · 0.95
RunMethod · 0.65
SchemaMethod · 0.65
ValidateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…