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

Function findDefaults

huma.go:282–293  ·  view source on GitHub ↗

findDefaults identifies struct fields with "default" tags and attempts to resolve their values using the provided registry.

(registry Registry, t reflect.Type)

Source from the content-addressed store, hash-verified

280// findDefaults identifies struct fields with "default" tags and attempts to resolve
281// their values using the provided registry.
282func findDefaults(registry Registry, t reflect.Type) *findResult[any] {
283 return findInType(t, nil, func(sf reflect.StructField, i []int) any {
284 if d := sf.Tag.Get("default"); d != "" {
285 if sf.Type.Kind() == reflect.Pointer && sf.Type.Elem().Kind() == reflect.Struct {
286 panic("pointers to structs cannot have default values")
287 }
288 s := registry.Schema(sf.Type, true, "")
289 return convertType(sf.Type.Name(), sf.Type, jsonTagValue(registry, sf.Name, s, d))
290 }
291 return nil
292 }, true)
293}
294
295type headerInfo struct {
296 Field reflect.StructField

Callers 1

RegisterFunction · 0.85

Calls 5

findInTypeFunction · 0.85
convertTypeFunction · 0.85
jsonTagValueFunction · 0.85
GetMethod · 0.65
SchemaMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…