MCPcopy Create free account
hub / github.com/compose-spec/compose-go / resolveContainer

Method resolveContainer

loader/reset.go:154–208  ·  view source on GitHub ↗

resolveContainer processes the children of a Sequence or Mapping node. AliasNodes must be kept as-is in the output Content; the resolved value is used only for tag inspection. Changing this will affect how the YAML library handles the document during decoding.

(node *yaml.Node, path tree.Path)

Source from the content-addressed store, hash-verified

152// for tag inspection. Changing this will affect how the YAML library handles the document
153// during decoding.
154func (p *ResetProcessor) resolveContainer(node *yaml.Node, path tree.Path) (*yaml.Node, error) {
155 switch node.Kind {
156 case yaml.SequenceNode:
157 var nodes []*yaml.Node
158 for idx, v := range node.Content {
159 next := path.Next(strconv.Itoa(idx))
160 resolved, err := p.resolveReset(v, next)
161 if err != nil {
162 return nil, err
163 }
164 if resolved == nil {
165 continue
166 }
167 if v.Kind == yaml.AliasNode {
168 nodes = append(nodes, v)
169 } else {
170 nodes = append(nodes, resolved)
171 }
172 }
173 node.Content = nodes
174 case yaml.MappingNode:
175 keys := map[string]int{}
176 var key string
177 var nodes []*yaml.Node
178 for idx, v := range node.Content {
179 if idx%2 == 0 {
180 key = v.Value
181 if line, seen := keys[key]; seen {
182 return nil, fmt.Errorf("line %d: mapping key %#v already defined at line %d", v.Line, key, line)
183 }
184 keys[key] = v.Line
185 } else {
186 resolved, err := p.resolveReset(v, path.Next(key))
187 if err != nil {
188 return nil, err
189 }
190 if resolved == nil {
191 continue
192 }
193 // Under the merge key `<<`, the YAML library only accepts an
194 // AliasNode value when its target is a MappingNode. An alias to a
195 // SequenceNode (the spec-allowed "sequence of mappings" form via an
196 // anchor) is rejected. Substitute the resolved target so the YAML
197 // library sees the underlying node directly for merge keys.
198 if v.Kind == yaml.AliasNode && key != "<<" {
199 nodes = append(nodes, node.Content[idx-1], v)
200 } else {
201 nodes = append(nodes, node.Content[idx-1], resolved)
202 }
203 }
204 }
205 node.Content = nodes
206 }
207 return node, nil
208}
209
210// subPath strips base from full to produce a relative path for cache storage.
211// Returns "" when full == base (the !reset/!override tag is on the node root itself).

Callers 1

cachedResolveMethod · 0.95

Calls 2

resolveResetMethod · 0.95
NextMethod · 0.80

Tested by

no test coverage detected