Pass the key node

This commit is contained in:
Dmitry
2023-08-25 10:42:17 +02:00
committed by quobix
parent 55da120b19
commit 6c24cd5940
12 changed files with 22 additions and 21 deletions

View File

@@ -118,7 +118,7 @@ func LocateRefNode(root *yaml.Node, idx *index.SpecIndex) (*yaml.Node, error) {
// ExtractObjectRaw will extract a typed Buildable[N] object from a root yaml.Node. The 'raw' aspect is
// that there is no NodeReference wrapper around the result returned, just the raw object.
func ExtractObjectRaw[T Buildable[N], N any](root *yaml.Node, idx *index.SpecIndex) (T, error, bool, string) {
func ExtractObjectRaw[T Buildable[N], N any](key, root *yaml.Node, idx *index.SpecIndex) (T, error, bool, string) {
var circError error
var isReference bool
var referenceValue string
@@ -143,7 +143,7 @@ func ExtractObjectRaw[T Buildable[N], N any](root *yaml.Node, idx *index.SpecInd
if err != nil {
return n, err, isReference, referenceValue
}
err = n.Build(root, idx)
err = n.Build(key, root, idx)
if err != nil {
return n, err, isReference, referenceValue
}
@@ -211,7 +211,7 @@ func ExtractObject[T Buildable[N], N any](label string, root *yaml.Node, idx *in
if ln == nil {
return NodeReference[T]{}, nil
}
err = n.Build(vn, idx)
err = n.Build(ln, vn, idx)
if err != nil {
return NodeReference[T]{}, err
}
@@ -316,7 +316,7 @@ func ExtractArray[T Buildable[N], N any](label string, root *yaml.Node, idx *ind
if err != nil {
return []ValueReference[T]{}, ln, vn, err
}
berr := n.Build(node, idx)
berr := n.Build(ln, node, idx)
if berr != nil {
return nil, ln, vn, berr
}
@@ -423,7 +423,7 @@ func ExtractMapNoLookupExtensions[PT Buildable[N], N any](
if err != nil {
return nil, err
}
berr := n.Build(node, idx)
berr := n.Build(currentKey, node, idx)
if berr != nil {
return nil, berr
}
@@ -531,7 +531,7 @@ func ExtractMapExtensions[PT Buildable[N], N any](
var n PT = new(N)
value = utils.NodeAlias(value)
_ = BuildModel(value, n)
err := n.Build(value, idx)
err := n.Build(label, value, idx)
if err != nil {
ec <- err
return

View File

@@ -157,7 +157,7 @@ func (p *PathItem) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
opErrorChan := make(chan error)
var buildOpFunc = func(op low.NodeReference[*Operation], ch chan<- bool, errCh chan<- error) {
er := op.Value.Build(op.ValueNode, idx)
er := op.Value.Build(op.KeyNode, op.ValueNode, idx)
if er != nil {
errCh <- er
}

View File

@@ -71,7 +71,7 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
var buildPathItem = func(cNode, pNode *yaml.Node, b chan<- pathBuildResult, e chan<- error) {
path := new(PathItem)
_ = low.BuildModel(pNode, path)
err := path.Build(pNode, idx)
err := path.Build(cNode, pNode, idx)
if err != nil {
e <- err
return

View File

@@ -43,7 +43,7 @@ func (r *Response) FindHeader(hType string) *low.ValueReference[*Header] {
}
// Build will extract schema, extensions, examples and headers from node
func (r *Response) Build(root *yaml.Node, idx *index.SpecIndex) error {
func (r *Response) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
root = utils.NodeAlias(root)
utils.CheckForMergeNodes(root)
r.Extensions = low.ExtractExtensions(root)

View File

@@ -27,7 +27,7 @@ func (r *Responses) GetExtensions() map[low.KeyReference[string]]low.ValueRefere
}
// Build will extract default value and extensions from node.
func (r *Responses) Build(root *yaml.Node, idx *index.SpecIndex) error {
func (r *Responses) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
root = utils.NodeAlias(root)
utils.CheckForMergeNodes(root)
r.Extensions = low.ExtractExtensions(root)

View File

@@ -34,7 +34,7 @@ func (s *Scopes) FindScope(scope string) *low.ValueReference[string] {
}
// Build will extract scope values and extensions from node.
func (s *Scopes) Build(root *yaml.Node, idx *index.SpecIndex) error {
func (s *Scopes) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
root = utils.NodeAlias(root)
utils.CheckForMergeNodes(root)
s.Extensions = low.ExtractExtensions(root)

View File

@@ -38,7 +38,7 @@ func (ss *SecurityScheme) GetExtensions() map[low.KeyReference[string]]low.Value
}
// Build will extract extensions and scopes from the node.
func (ss *SecurityScheme) Build(root *yaml.Node, idx *index.SpecIndex) error {
func (ss *SecurityScheme) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
root = utils.NodeAlias(root)
utils.CheckForMergeNodes(root)
ss.Extensions = low.ExtractExtensions(root)

View File

@@ -57,7 +57,7 @@ func (cb *Callback) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
if strings.HasPrefix(currentCB.Value, "x-") {
continue // ignore extension.
}
callback, eErr, _, rv := low.ExtractObjectRaw[*PathItem](callbackNode, idx)
callback, eErr, _, rv := low.ExtractObjectRaw[*PathItem](currentCB, callbackNode, idx)
if eErr != nil {
return eErr
}

View File

@@ -235,7 +235,8 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.
// build.
_ = low.BuildModel(value, n)
err = n.Build(value, idx)
// todo: label is a key or?
err = n.Build(label, value, idx)
if err != nil {
ec <- err
return

View File

@@ -117,7 +117,7 @@ func extractInfo(info *datamodel.SpecInfo, doc *Document, idx *index.SpecIndex)
if vn != nil {
ir := base.Info{}
_ = low.BuildModel(vn, &ir)
_ = ir.Build(vn, idx)
_ = ir.Build(ln, vn, idx)
nr := low.NodeReference[*base.Info]{Value: &ir, ValueNode: vn, KeyNode: ln}
doc.Info = nr
}
@@ -172,7 +172,7 @@ func extractServers(info *datamodel.SpecInfo, doc *Document, idx *index.SpecInde
if utils.IsNodeMap(srvN) {
srvr := Server{}
_ = low.BuildModel(srvN, &srvr)
_ = srvr.Build(srvN, idx)
_ = srvr.Build(ln, srvN, idx)
servers = append(servers, low.ValueReference[*Server]{
Value: &srvr,
ValueNode: srvN,
@@ -198,7 +198,7 @@ func extractTags(info *datamodel.SpecInfo, doc *Document, idx *index.SpecIndex)
if utils.IsNodeMap(tagN) {
tag := base.Tag{}
_ = low.BuildModel(tagN, &tag)
if err := tag.Build(tagN, idx); err != nil {
if err := tag.Build(ln, tagN, idx); err != nil {
return err
}
tags = append(tags, low.ValueReference[*base.Tag]{
@@ -221,7 +221,7 @@ func extractPaths(info *datamodel.SpecInfo, doc *Document, idx *index.SpecIndex)
_, ln, vn := utils.FindKeyNodeFull(PathsLabel, info.RootNode.Content[0].Content)
if vn != nil {
ir := Paths{}
err := ir.Build(vn, idx)
err := ir.Build(ln, vn, idx)
if err != nil {
return err
}

View File

@@ -142,7 +142,7 @@ func (p *PathItem) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
if utils.IsNodeMap(srvN) {
srvr := new(Server)
_ = low.BuildModel(srvN, srvr)
srvr.Build(srvN, idx)
srvr.Build(ln, srvN, idx)
servers = append(servers, low.ValueReference[*Server]{
Value: srvr,
ValueNode: srvN,
@@ -274,7 +274,7 @@ func (p *PathItem) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
opErrorChan := make(chan error)
buildOpFunc := func(op low.NodeReference[*Operation], ch chan<- bool, errCh chan<- error, ref string) {
er := op.Value.Build(op.ValueNode, idx)
er := op.Value.Build(op.KeyNode, op.ValueNode, idx)
if ref != "" {
op.Value.Reference.Reference = ref
}

View File

@@ -102,7 +102,7 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
path := new(PathItem)
_ = low.BuildModel(pNode, path)
err := path.Build(pNode, idx)
err := path.Build(cNode, pNode, idx)
if err != nil {
e <- err
return