(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

@@ -59,6 +59,12 @@ type NodeReference[T any] struct {
// The yaml.Node that is the key, that contains the value.
KeyNode *yaml.Node
// Is this value actually a reference in the original tree?
IsReference bool
// If HasReference is true, then Reference contains the original $ref value.
Reference string
}
// KeyReference is a low-level container for key nodes holding a Value of type T. A KeyNode is a pointer to the
@@ -81,6 +87,12 @@ type ValueReference[T any] struct {
// The yaml.Node that holds the referenced value
ValueNode *yaml.Node
// Is this value actually a reference in the original tree?
IsReference bool
// If HasReference is true, then Reference contains the original $ref value.
Reference string
}
// IsEmpty will return true if this reference has no key or value nodes assigned (it's been ignored)