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

Method Validate

validate.go:891–903  ·  view source on GitHub ↗

Validate the inputs. The type should be the Go struct with validation field tags and the value should be e.g. JSON loaded into an `any`. A list of errors is returned if validation failed, otherwise `nil`. type MyExample struct { Name string `json:"name" maxLength:"5"` Age int `json:"age" minim

(typ reflect.Type, value any)

Source from the content-addressed store, hash-verified

889// fmt.Println("Validation error", errs)
890// }
891func (v *ModelValidator) Validate(typ reflect.Type, value any) []error {
892 v.pb.Reset()
893 v.result.Reset()
894
895 s := v.registry.Schema(typ, true, typ.Name())
896
897 Validate(v.registry, s, v.pb, ModeReadFromServer, value, v.result)
898
899 if len(v.result.Errors) > 0 {
900 return v.result.Errors
901 }
902 return nil
903}
904
905// The following is borrowed from the Google UUID package:
906// https://github.com/google/uuid/blob/v1.6.0/uuid.go

Callers 14

ExampleModelValidatorFunction · 0.95
TestSchemaOldFunction · 0.45
BenchmarkSchemaFunction · 0.45
BenchmarkSchemaErrorsFunction · 0.45
TestValidateFunction · 0.45
BenchmarkValidateFunction · 0.45
BenchmarkRawBunRouterFunction · 0.45
BenchmarkRawEchoFunction · 0.45

Calls 3

ValidateFunction · 0.85
SchemaMethod · 0.65
ResetMethod · 0.45

Tested by 14

ExampleModelValidatorFunction · 0.76
TestSchemaOldFunction · 0.36
BenchmarkSchemaFunction · 0.36
BenchmarkSchemaErrorsFunction · 0.36
TestValidateFunction · 0.36
BenchmarkValidateFunction · 0.36
BenchmarkRawBunRouterFunction · 0.36
BenchmarkRawEchoFunction · 0.36