An enormous amount of surgery on the low level model.

Every `Build()` method now requires a `context.Context`. This is so the rolodex knows where to resolve from when locating relative links. Without knowing where we are, there is no way to resolve anything. This new mechanism allows the model to recurse across as many files as required to locate references, without loosing track of where we are in the process.

Signed-off-by: quobix <dave@quobix.com>
This commit is contained in:
quobix
2023-10-23 15:04:34 -04:00
parent 3bf830c2b3
commit 8717b3cd33
68 changed files with 1343 additions and 1002 deletions

View File

@@ -64,6 +64,7 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
Definition: definitionPath,
Node: node.Content[i+1],
Path: jsonPath,
Index: index,
}
isRef, _, _ := utils.IsNodeRefValue(node.Content[i+1])
@@ -120,6 +121,7 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
Definition: definitionPath,
Node: prop,
Path: jsonPath,
Index: index,
}
isRef, _, _ := utils.IsNodeRefValue(prop)
@@ -165,6 +167,7 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
Definition: definitionPath,
Node: element,
Path: jsonPath,
Index: index,
}
isRef, _, _ := utils.IsNodeRefValue(element)
@@ -341,6 +344,7 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
Name: name,
Node: node,
Path: p,
Index: index,
}
// add to raw sequenced refs
@@ -367,6 +371,7 @@ func (index *SpecIndex) ExtractRefs(node, parent *yaml.Node, seenPath []string,
Name: ref.Name,
Node: &copiedNode,
Path: p,
Index: index,
}
// protect this data using a copy, prevent the resolver from destroying things.
index.refsWithSiblings[value] = copied
@@ -592,6 +597,11 @@ func (index *SpecIndex) ExtractComponentsFromRefs(refs []*Reference) []*Referenc
locate := func(ref *Reference, refIndex int, sequence []*ReferenceMapped) {
located := index.FindComponent(ref.FullDefinition, ref.Node)
if located != nil {
if located.Index == nil {
index.logger.Warn("located component has no index", "component", located.FullDefinition)
}
index.refLock.Lock()
// have we already mapped this?
if index.allMappedRefs[ref.FullDefinition] == nil {