mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
Pass the key node
This commit is contained in:
@@ -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
|
// 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.
|
// 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 circError error
|
||||||
var isReference bool
|
var isReference bool
|
||||||
var referenceValue string
|
var referenceValue string
|
||||||
@@ -143,7 +143,7 @@ func ExtractObjectRaw[T Buildable[N], N any](root *yaml.Node, idx *index.SpecInd
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err, isReference, referenceValue
|
return n, err, isReference, referenceValue
|
||||||
}
|
}
|
||||||
err = n.Build(root, idx)
|
err = n.Build(key, root, idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return n, err, isReference, referenceValue
|
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 {
|
if ln == nil {
|
||||||
return NodeReference[T]{}, nil
|
return NodeReference[T]{}, nil
|
||||||
}
|
}
|
||||||
err = n.Build(vn, idx)
|
err = n.Build(ln, vn, idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return NodeReference[T]{}, err
|
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 {
|
if err != nil {
|
||||||
return []ValueReference[T]{}, ln, vn, err
|
return []ValueReference[T]{}, ln, vn, err
|
||||||
}
|
}
|
||||||
berr := n.Build(node, idx)
|
berr := n.Build(ln, node, idx)
|
||||||
if berr != nil {
|
if berr != nil {
|
||||||
return nil, ln, vn, berr
|
return nil, ln, vn, berr
|
||||||
}
|
}
|
||||||
@@ -423,7 +423,7 @@ func ExtractMapNoLookupExtensions[PT Buildable[N], N any](
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
berr := n.Build(node, idx)
|
berr := n.Build(currentKey, node, idx)
|
||||||
if berr != nil {
|
if berr != nil {
|
||||||
return nil, berr
|
return nil, berr
|
||||||
}
|
}
|
||||||
@@ -531,7 +531,7 @@ func ExtractMapExtensions[PT Buildable[N], N any](
|
|||||||
var n PT = new(N)
|
var n PT = new(N)
|
||||||
value = utils.NodeAlias(value)
|
value = utils.NodeAlias(value)
|
||||||
_ = BuildModel(value, n)
|
_ = BuildModel(value, n)
|
||||||
err := n.Build(value, idx)
|
err := n.Build(label, value, idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec <- err
|
ec <- err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ func (p *PathItem) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
opErrorChan := make(chan error)
|
opErrorChan := make(chan error)
|
||||||
|
|
||||||
var buildOpFunc = func(op low.NodeReference[*Operation], ch chan<- bool, errCh 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 {
|
if er != nil {
|
||||||
errCh <- er
|
errCh <- er
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
var buildPathItem = func(cNode, pNode *yaml.Node, b chan<- pathBuildResult, e chan<- error) {
|
||||||
path := new(PathItem)
|
path := new(PathItem)
|
||||||
_ = low.BuildModel(pNode, path)
|
_ = low.BuildModel(pNode, path)
|
||||||
err := path.Build(pNode, idx)
|
err := path.Build(cNode, pNode, idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e <- err
|
e <- err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func (r *Response) FindHeader(hType string) *low.ValueReference[*Header] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build will extract schema, extensions, examples and headers from node
|
// 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)
|
root = utils.NodeAlias(root)
|
||||||
utils.CheckForMergeNodes(root)
|
utils.CheckForMergeNodes(root)
|
||||||
r.Extensions = low.ExtractExtensions(root)
|
r.Extensions = low.ExtractExtensions(root)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func (r *Responses) GetExtensions() map[low.KeyReference[string]]low.ValueRefere
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build will extract default value and extensions from node.
|
// 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)
|
root = utils.NodeAlias(root)
|
||||||
utils.CheckForMergeNodes(root)
|
utils.CheckForMergeNodes(root)
|
||||||
r.Extensions = low.ExtractExtensions(root)
|
r.Extensions = low.ExtractExtensions(root)
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (s *Scopes) FindScope(scope string) *low.ValueReference[string] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build will extract scope values and extensions from node.
|
// 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)
|
root = utils.NodeAlias(root)
|
||||||
utils.CheckForMergeNodes(root)
|
utils.CheckForMergeNodes(root)
|
||||||
s.Extensions = low.ExtractExtensions(root)
|
s.Extensions = low.ExtractExtensions(root)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (ss *SecurityScheme) GetExtensions() map[low.KeyReference[string]]low.Value
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build will extract extensions and scopes from the node.
|
// 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)
|
root = utils.NodeAlias(root)
|
||||||
utils.CheckForMergeNodes(root)
|
utils.CheckForMergeNodes(root)
|
||||||
ss.Extensions = low.ExtractExtensions(root)
|
ss.Extensions = low.ExtractExtensions(root)
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (cb *Callback) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
if strings.HasPrefix(currentCB.Value, "x-") {
|
if strings.HasPrefix(currentCB.Value, "x-") {
|
||||||
continue // ignore extension.
|
continue // ignore extension.
|
||||||
}
|
}
|
||||||
callback, eErr, _, rv := low.ExtractObjectRaw[*PathItem](callbackNode, idx)
|
callback, eErr, _, rv := low.ExtractObjectRaw[*PathItem](currentCB, callbackNode, idx)
|
||||||
if eErr != nil {
|
if eErr != nil {
|
||||||
return eErr
|
return eErr
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,7 +235,8 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.
|
|||||||
|
|
||||||
// build.
|
// build.
|
||||||
_ = low.BuildModel(value, n)
|
_ = low.BuildModel(value, n)
|
||||||
err = n.Build(value, idx)
|
// todo: label is a key or?
|
||||||
|
err = n.Build(label, value, idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ec <- err
|
ec <- err
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ func extractInfo(info *datamodel.SpecInfo, doc *Document, idx *index.SpecIndex)
|
|||||||
if vn != nil {
|
if vn != nil {
|
||||||
ir := base.Info{}
|
ir := base.Info{}
|
||||||
_ = low.BuildModel(vn, &ir)
|
_ = low.BuildModel(vn, &ir)
|
||||||
_ = ir.Build(vn, idx)
|
_ = ir.Build(ln, vn, idx)
|
||||||
nr := low.NodeReference[*base.Info]{Value: &ir, ValueNode: vn, KeyNode: ln}
|
nr := low.NodeReference[*base.Info]{Value: &ir, ValueNode: vn, KeyNode: ln}
|
||||||
doc.Info = nr
|
doc.Info = nr
|
||||||
}
|
}
|
||||||
@@ -172,7 +172,7 @@ func extractServers(info *datamodel.SpecInfo, doc *Document, idx *index.SpecInde
|
|||||||
if utils.IsNodeMap(srvN) {
|
if utils.IsNodeMap(srvN) {
|
||||||
srvr := Server{}
|
srvr := Server{}
|
||||||
_ = low.BuildModel(srvN, &srvr)
|
_ = low.BuildModel(srvN, &srvr)
|
||||||
_ = srvr.Build(srvN, idx)
|
_ = srvr.Build(ln, srvN, idx)
|
||||||
servers = append(servers, low.ValueReference[*Server]{
|
servers = append(servers, low.ValueReference[*Server]{
|
||||||
Value: &srvr,
|
Value: &srvr,
|
||||||
ValueNode: srvN,
|
ValueNode: srvN,
|
||||||
@@ -198,7 +198,7 @@ func extractTags(info *datamodel.SpecInfo, doc *Document, idx *index.SpecIndex)
|
|||||||
if utils.IsNodeMap(tagN) {
|
if utils.IsNodeMap(tagN) {
|
||||||
tag := base.Tag{}
|
tag := base.Tag{}
|
||||||
_ = low.BuildModel(tagN, &tag)
|
_ = low.BuildModel(tagN, &tag)
|
||||||
if err := tag.Build(tagN, idx); err != nil {
|
if err := tag.Build(ln, tagN, idx); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
tags = append(tags, low.ValueReference[*base.Tag]{
|
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)
|
_, ln, vn := utils.FindKeyNodeFull(PathsLabel, info.RootNode.Content[0].Content)
|
||||||
if vn != nil {
|
if vn != nil {
|
||||||
ir := Paths{}
|
ir := Paths{}
|
||||||
err := ir.Build(vn, idx)
|
err := ir.Build(ln, vn, idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ func (p *PathItem) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
if utils.IsNodeMap(srvN) {
|
if utils.IsNodeMap(srvN) {
|
||||||
srvr := new(Server)
|
srvr := new(Server)
|
||||||
_ = low.BuildModel(srvN, srvr)
|
_ = low.BuildModel(srvN, srvr)
|
||||||
srvr.Build(srvN, idx)
|
srvr.Build(ln, srvN, idx)
|
||||||
servers = append(servers, low.ValueReference[*Server]{
|
servers = append(servers, low.ValueReference[*Server]{
|
||||||
Value: srvr,
|
Value: srvr,
|
||||||
ValueNode: srvN,
|
ValueNode: srvN,
|
||||||
@@ -274,7 +274,7 @@ func (p *PathItem) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
opErrorChan := make(chan error)
|
opErrorChan := make(chan error)
|
||||||
|
|
||||||
buildOpFunc := func(op low.NodeReference[*Operation], ch chan<- bool, errCh chan<- error, ref string) {
|
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 != "" {
|
if ref != "" {
|
||||||
op.Value.Reference.Reference = ref
|
op.Value.Reference.Reference = ref
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
|
|
||||||
path := new(PathItem)
|
path := new(PathItem)
|
||||||
_ = low.BuildModel(pNode, path)
|
_ = low.BuildModel(pNode, path)
|
||||||
err := path.Build(pNode, idx)
|
err := path.Build(cNode, pNode, idx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e <- err
|
e <- err
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user