MCPcopy Index your code
hub / github.com/docker/docker-agent / stripNullFromRequiredTypes

Function stripNullFromRequiredTypes

pkg/tools/schema.go:65–88  ·  view source on GitHub ↗

stripNullFromRequiredTypes recursively walks a JSON Schema map and removes "null" from the type of every property listed in its parent's "required" array. Optional properties are left untouched.

(schema map[string]any)

Source from the content-addressed store, hash-verified

63// "null" from the type of every property listed in its parent's "required"
64// array. Optional properties are left untouched.
65func stripNullFromRequiredTypes(schema map[string]any) {
66 props, ok := schema["properties"].(map[string]any)
67 if !ok {
68 return
69 }
70
71 required := requiredSet(schema)
72
73 for name, v := range props {
74 prop, ok := v.(map[string]any)
75 if !ok {
76 continue
77 }
78
79 if required[name] {
80 removeNullFromType(prop)
81 }
82
83 stripNullFromRequiredTypes(prop)
84 if items, ok := prop["items"].(map[string]any); ok {
85 stripNullFromRequiredTypes(items)
86 }
87 }
88}
89
90func requiredSet(schema map[string]any) map[string]bool {
91 set := map[string]bool{}

Callers 1

SchemaToMapFunction · 0.85

Calls 2

requiredSetFunction · 0.85
removeNullFromTypeFunction · 0.85

Tested by

no test coverage detected