feat: add attribute to schema model

This commit is contained in:
Tristan Cartledge
2023-04-17 12:41:59 +00:00
committed by Dave Shanley
parent 4c331de207
commit 99bf12c1c7
6 changed files with 137 additions and 111 deletions

View File

@@ -90,6 +90,7 @@ type Schema struct {
PropertyNames low.NodeReference[*SchemaProxy]
UnevaluatedItems low.NodeReference[*SchemaProxy]
UnevaluatedProperties low.NodeReference[*SchemaProxy]
Anchor low.NodeReference[string]
// Compatible with all versions
Title low.NodeReference[string]
@@ -394,6 +395,9 @@ func (s *Schema) Hash() [32]byte {
if !s.UnevaluatedItems.IsEmpty() {
d = append(d, low.GenerateHashString(s.UnevaluatedItems.Value))
}
if !s.Anchor.IsEmpty() {
d = append(d, fmt.Sprint(s.Anchor.Value))
}
depSchemasKeys := make([]string, len(s.DependentSchemas.Value))
z = 0
@@ -514,6 +518,7 @@ func (s *Schema) GetExtensions() map[low.KeyReference[string]]low.ValueReference
// - PropertyNames
// - UnevaluatedItems
// - UnevaluatedProperties
// - Anchor
func (s *Schema) Build(root *yaml.Node, idx *index.SpecIndex) error {
s.Reference = new(low.Reference)
if h, _, _ := utils.IsNodeRefValue(root); h {
@@ -615,6 +620,14 @@ func (s *Schema) Build(root *yaml.Node, idx *index.SpecIndex) error {
}
}
// handle anchor if set. (3.1)
_, anchorLabel, anchorNode := utils.FindKeyNodeFullTop(AnchorLabel, root.Content)
if anchorNode != nil {
s.Anchor = low.NodeReference[string]{
Value: anchorNode.Value, KeyNode: anchorLabel, ValueNode: anchorLabel,
}
}
// handle example if set. (3.0)
_, expLabel, expNode := utils.FindKeyNodeFull(ExampleLabel, root.Content)
if expNode != nil {