(feat): Added Reference tracking to low-level model #25

When building a document, everything that IS NOT a schema is auto-resolved in the model, this is very convenient because it creates a nice tree to explore and there is no need to perform lookups to when using `$ref` instead of inline definitions.

The issue is however being able to determine if the node was originally a reference or not, that data was lost, including the name of the reference used. This use case surfaced in issue #25, where the need to know what is and what is not referenced has different requirements for different applications.

This update now tracks that data and makes it available in `NodeReference` and `ValueReference` for every property.

Signed-off-by: Dave Shanley <dave@quobix.com>
This commit is contained in:
Dave Shanley
2022-12-03 12:30:27 -05:00
parent 0f774a4c4b
commit b5436e8d4e
5 changed files with 115 additions and 40 deletions

View File

@@ -48,7 +48,7 @@ func (cb *Callback) Build(root *yaml.Node, idx *index.SpecIndex) error {
currentCB = callbackNode
continue
}
callback, eErr := low.ExtractObjectRaw[*PathItem](callbackNode, idx)
callback, eErr, isRef, rv := low.ExtractObjectRaw[*PathItem](callbackNode, idx)
if eErr != nil {
return eErr
}
@@ -56,8 +56,10 @@ func (cb *Callback) Build(root *yaml.Node, idx *index.SpecIndex) error {
Value: currentCB.Value,
KeyNode: currentCB,
}] = low.ValueReference[*PathItem]{
Value: callback,
ValueNode: callbackNode,
Value: callback,
ValueNode: callbackNode,
IsReference: isRef,
Reference: rv,
}
}
if len(callbacks) > 0 {