mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 12:37:48 +00:00
fix: cleanup tests
This commit is contained in:
@@ -779,157 +779,6 @@ func ExtractMapExtensions[PT Buildable[N], N any](
|
||||
return nil, labelNode, valueNode, nil
|
||||
}
|
||||
|
||||
// ExtractMapExtensions will extract a map of KeyReference and ValueReference from a root yaml.Node. The 'label' is
|
||||
// used to locate the node to be extracted from the root node supplied. Supply a bit to decide if extensions should
|
||||
// be included or not. required in some use cases.
|
||||
//
|
||||
// The second return value is the yaml.Node found for the 'label' and the third return value is the yaml.Node
|
||||
// found for the value extracted from the label node.
|
||||
func ExtractMapExtensionsOld[PT Buildable[N], N any](
|
||||
ctx context.Context,
|
||||
label string,
|
||||
root *yaml.Node,
|
||||
idx *index.SpecIndex,
|
||||
extensions bool,
|
||||
) (*orderedmap.Map[KeyReference[string], ValueReference[PT]], *yaml.Node, *yaml.Node, error) {
|
||||
var referenceValue string
|
||||
var labelNode, valueNode *yaml.Node
|
||||
var circError error
|
||||
root = utils.NodeAlias(root)
|
||||
if rf, rl, rv := utils.IsNodeRefValue(root); rf {
|
||||
// locate reference in index.
|
||||
ref, fIdx, err, fCtx := LocateRefNodeWithContext(ctx, root, idx)
|
||||
if ref != nil {
|
||||
valueNode = ref
|
||||
labelNode = rl
|
||||
referenceValue = rv
|
||||
ctx = fCtx
|
||||
idx = fIdx
|
||||
if err != nil {
|
||||
circError = err
|
||||
}
|
||||
} else {
|
||||
return nil, labelNode, valueNode, fmt.Errorf("map build failed: reference cannot be found: %s",
|
||||
root.Content[1].Value)
|
||||
}
|
||||
} else {
|
||||
_, labelNode, valueNode = utils.FindKeyNodeFull(label, root.Content)
|
||||
valueNode = utils.NodeAlias(valueNode)
|
||||
if valueNode != nil {
|
||||
if h, _, rvt := utils.IsNodeRefValue(valueNode); h {
|
||||
ref, fIdx, err, nCtx := LocateRefNodeWithContext(ctx, valueNode, idx)
|
||||
if ref != nil {
|
||||
valueNode = ref
|
||||
referenceValue = rvt
|
||||
idx = fIdx
|
||||
ctx = nCtx
|
||||
if err != nil {
|
||||
circError = err
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
return nil, labelNode, valueNode, fmt.Errorf("map build failed: reference cannot be found: %s",
|
||||
err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if valueNode != nil {
|
||||
var currentLabelNode *yaml.Node
|
||||
valueMap := orderedmap.New[KeyReference[string], ValueReference[PT]]()
|
||||
|
||||
// TODO: Convert to datamodel.TranslatePipeline.
|
||||
bChan := make(chan mappingResult[PT])
|
||||
eChan := make(chan error)
|
||||
|
||||
buildMap := func(nctx context.Context, label *yaml.Node, value *yaml.Node, c chan mappingResult[PT], ec chan<- error, ref string, fIdx *index.SpecIndex) {
|
||||
var n PT = new(N)
|
||||
value = utils.NodeAlias(value)
|
||||
_ = BuildModel(value, n)
|
||||
err := n.Build(nctx, label, value, fIdx)
|
||||
if err != nil {
|
||||
ec <- err
|
||||
return
|
||||
}
|
||||
|
||||
if ref != "" {
|
||||
SetReference(n, ref, nil)
|
||||
}
|
||||
|
||||
c <- mappingResult[PT]{
|
||||
k: KeyReference[string]{
|
||||
KeyNode: label,
|
||||
Value: label.Value,
|
||||
},
|
||||
v: ValueReference[PT]{
|
||||
Value: n,
|
||||
ValueNode: value,
|
||||
// Reference: ref,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
totalKeys := 0
|
||||
for i, en := range valueNode.Content {
|
||||
en = utils.NodeAlias(en)
|
||||
referenceValue = ""
|
||||
if i%2 == 0 {
|
||||
currentLabelNode = en
|
||||
continue
|
||||
}
|
||||
|
||||
foundIndex := idx
|
||||
foundContext := ctx
|
||||
|
||||
// check our valueNode isn't a reference still.
|
||||
if h, _, refVal := utils.IsNodeRefValue(en); h {
|
||||
ref, fIdx, err, nCtx := LocateRefNodeWithContext(ctx, en, idx)
|
||||
if ref != nil {
|
||||
en = ref
|
||||
referenceValue = refVal
|
||||
if fIdx != nil {
|
||||
foundIndex = fIdx
|
||||
}
|
||||
foundContext = nCtx
|
||||
if err != nil {
|
||||
circError = err
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
return nil, labelNode, valueNode, fmt.Errorf("flat map build failed: reference cannot be found: %s",
|
||||
err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !extensions {
|
||||
if strings.HasPrefix(currentLabelNode.Value, "x-") {
|
||||
continue // yo, don't pay any attention to extensions, not here anyway.
|
||||
}
|
||||
}
|
||||
totalKeys++
|
||||
go buildMap(foundContext, currentLabelNode, en, bChan, eChan, referenceValue, foundIndex)
|
||||
}
|
||||
|
||||
completedKeys := 0
|
||||
for completedKeys < totalKeys {
|
||||
select {
|
||||
case err := <-eChan:
|
||||
return valueMap, labelNode, valueNode, err
|
||||
case res := <-bChan:
|
||||
completedKeys++
|
||||
valueMap.Set(res.k, res.v)
|
||||
}
|
||||
}
|
||||
if circError != nil && !idx.AllowCircularReferenceResolving() {
|
||||
return valueMap, labelNode, valueNode, circError
|
||||
}
|
||||
return valueMap, labelNode, valueNode, nil
|
||||
}
|
||||
return nil, labelNode, valueNode, nil
|
||||
}
|
||||
|
||||
// ExtractMap will extract a map of KeyReference and ValueReference from a root yaml.Node. The 'label' is
|
||||
// used to locate the node to be extracted from the root node supplied.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user