MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / normalizeArguments

Function normalizeArguments

internal/artifact/encode.go:109–130  ·  view source on GitHub ↗

normalizeArguments coerces the arguments value into []map[string]any so it serializes as a stable YAML sequence of maps. Accepts []map[string]any or []any (e.g. JSON-decoded) whose elements are map[string]any. Anything it cannot interpret as a map is skipped.

(v any)

Source from the content-addressed store, hash-verified

107// []any (e.g. JSON-decoded) whose elements are map[string]any. Anything it
108// cannot interpret as a map is skipped.
109func normalizeArguments(v any) []map[string]any {
110 switch xs := v.(type) {
111 case []map[string]any:
112 if len(xs) == 0 {
113 return nil
114 }
115 return xs
116 case []any:
117 out := make([]map[string]any, 0, len(xs))
118 for _, el := range xs {
119 if m := toStringMap(el); m != nil {
120 out = append(out, m)
121 }
122 }
123 if len(out) == 0 {
124 return nil
125 }
126 return out
127 default:
128 return nil
129 }
130}
131
132func toStringMap(v any) map[string]any {
133 if m, ok := v.(map[string]any); ok {

Callers 1

EncodeFunction · 0.85

Calls 1

toStringMapFunction · 0.85

Tested by

no test coverage detected