MCPcopy Index your code
hub / github.com/docker/cli / convertToStringKeysRecursive

Function convertToStringKeysRecursive

cli/compose/loader/loader.go:360–391  ·  view source on GitHub ↗

keys needs to be converted to strings for jsonschema

(value any, keyPrefix string)

Source from the content-addressed store, hash-verified

358
359// keys needs to be converted to strings for jsonschema
360func convertToStringKeysRecursive(value any, keyPrefix string) (any, error) {
361 if mapping, ok := value.(map[string]any); ok {
362 dict := make(map[string]any)
363 for key, entry := range mapping {
364 var newKeyPrefix string
365 if keyPrefix == "" {
366 newKeyPrefix = key
367 } else {
368 newKeyPrefix = fmt.Sprintf("%s.%s", keyPrefix, key)
369 }
370 convertedEntry, err := convertToStringKeysRecursive(entry, newKeyPrefix)
371 if err != nil {
372 return nil, err
373 }
374 dict[key] = convertedEntry
375 }
376 return dict, nil
377 }
378 if list, ok := value.([]any); ok {
379 var convertedList []any
380 for index, entry := range list {
381 newKeyPrefix := fmt.Sprintf("%s[%d]", keyPrefix, index)
382 convertedEntry, err := convertToStringKeysRecursive(entry, newKeyPrefix)
383 if err != nil {
384 return nil, err
385 }
386 convertedList = append(convertedList, convertedEntry)
387 }
388 return convertedList, nil
389 }
390 return value, nil
391}
392
393// LoadServices produces a ServiceConfig map from a compose file Dict
394// the servicesDict is not validated if directly used. Use Load() to enable validation

Callers 1

ParseYAMLFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…