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

Function isEmptyValue

openapi.go:38–54  ·  view source on GitHub ↗

isEmptyValue returns true if the given value is empty. This is a copy of isEmptyValue from encoding/json to help determine when to write a field with `omitempty` set.

(v reflect.Value)

Source from the content-addressed store, hash-verified

36// isEmptyValue from encoding/json to help determine when to write a field
37// with `omitempty` set.
38func isEmptyValue(v reflect.Value) bool {
39 switch v.Kind() {
40 case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
41 return v.Len() == 0
42 case reflect.Bool:
43 return !v.Bool()
44 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
45 return v.Int() == 0
46 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
47 return v.Uint() == 0
48 case reflect.Float32, reflect.Float64:
49 return v.Float() == 0
50 case reflect.Interface, reflect.Pointer:
51 return v.IsNil()
52 }
53 return false
54}
55
56// isNilValue returns true if the given value is nil.
57func isNilValue(v any) bool {

Callers 1

marshalJSONFunction · 0.85

Calls 1

LenMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…