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

Function jsonTagValue

schema.go:517–547  ·  view source on GitHub ↗
(r Registry, fieldName string, s *Schema, value string)

Source from the content-addressed store, hash-verified

515}
516
517func jsonTagValue(r Registry, fieldName string, s *Schema, value string) any {
518 if s.Ref != "" {
519 s = r.SchemaFromRef(s.Ref)
520 if s == nil {
521 return nil
522 }
523 }
524
525 // Special case: strings don't need quotes.
526 if s.Type == TypeString {
527 return value
528 }
529
530 // Special case: array of strings with comma-separated values and no quotes.
531 if s.Type == TypeArray && s.Items != nil && s.Items.Type == TypeString && value[0] != '[' {
532 var values []string
533 for s := range strings.SplitSeq(value, ",") {
534 values = append(values, strings.TrimSpace(s))
535 }
536 return values
537 }
538
539 var v any
540 if err := json.Unmarshal([]byte(value), &v); err != nil {
541 panic(fmt.Errorf("invalid %s tag value '%s' for field '%s': %w", s.Type, value, fieldName, err))
542 }
543
544 ensureType(r, fieldName, s, value, v)
545
546 return v
547}
548
549// jsonTag returns a value of the schema's type for the given tag string.
550// Uses JSON parsing if the schema is not a string.

Callers 3

jsonTagFunction · 0.85
SchemaFromFieldFunction · 0.85
findDefaultsFunction · 0.85

Calls 3

ensureTypeFunction · 0.85
SchemaFromRefMethod · 0.65
UnmarshalMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…