mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 12:37:48 +00:00
Tidy code.
This commit is contained in:
@@ -59,20 +59,18 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
root = utils.NodeAlias(root)
|
root = utils.NodeAlias(root)
|
||||||
utils.CheckForMergeNodes(root)
|
utils.CheckForMergeNodes(root)
|
||||||
p.Extensions = low.ExtractExtensions(root)
|
p.Extensions = low.ExtractExtensions(root)
|
||||||
// skip := false
|
|
||||||
// var currentNode *yaml.Node
|
|
||||||
|
|
||||||
// Translate YAML nodes to pathsMap using `TranslatePipeline`.
|
// Translate YAML nodes to pathsMap using `TranslatePipeline`.
|
||||||
type pathBuildResult struct {
|
type pathBuildResult struct {
|
||||||
key low.KeyReference[string]
|
key low.KeyReference[string]
|
||||||
value low.ValueReference[*PathItem]
|
value low.ValueReference[*PathItem]
|
||||||
}
|
}
|
||||||
type nodeItem struct {
|
type buildInput struct {
|
||||||
currentNode *yaml.Node
|
currentNode *yaml.Node
|
||||||
pathNode *yaml.Node
|
pathNode *yaml.Node
|
||||||
}
|
}
|
||||||
pathsMap := make(map[low.KeyReference[string]]low.ValueReference[*PathItem])
|
pathsMap := make(map[low.KeyReference[string]]low.ValueReference[*PathItem])
|
||||||
in := make(chan nodeItem)
|
in := make(chan buildInput)
|
||||||
out := make(chan pathBuildResult)
|
out := make(chan pathBuildResult)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -102,7 +100,7 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case in <- nodeItem{
|
case in <- buildInput{
|
||||||
currentNode: currentNode,
|
currentNode: currentNode,
|
||||||
pathNode: pathNode,
|
pathNode: pathNode,
|
||||||
}:
|
}:
|
||||||
@@ -131,7 +129,7 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
translateFunc := func(value nodeItem) (retval pathBuildResult, _ error) {
|
translateFunc := func(value buildInput) (retval pathBuildResult, _ error) {
|
||||||
pNode := value.pathNode
|
pNode := value.pathNode
|
||||||
cNode := value.currentNode
|
cNode := value.currentNode
|
||||||
path := new(PathItem)
|
path := new(PathItem)
|
||||||
@@ -151,7 +149,7 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
err := datamodel.TranslatePipeline[nodeItem, pathBuildResult](in, out, translateFunc)
|
err := datamodel.TranslatePipeline[buildInput, pathBuildResult](in, out, translateFunc)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ type componentBuildResult[T any] struct {
|
|||||||
value low.ValueReference[T]
|
value low.ValueReference[T]
|
||||||
}
|
}
|
||||||
|
|
||||||
type inputValue struct {
|
type componentInput struct {
|
||||||
node *yaml.Node
|
node *yaml.Node
|
||||||
currentLabel *yaml.Node
|
currentLabel *yaml.Node
|
||||||
}
|
}
|
||||||
@@ -236,7 +236,7 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.
|
|||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
in := make(chan inputValue)
|
in := make(chan componentInput)
|
||||||
out := make(chan componentBuildResult[T])
|
out := make(chan componentBuildResult[T])
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(2) // input and output goroutines.
|
wg.Add(2) // input and output goroutines.
|
||||||
@@ -257,7 +257,7 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.
|
|||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case in <- inputValue{
|
case in <- componentInput{
|
||||||
node: node,
|
node: node,
|
||||||
currentLabel: currentLabel,
|
currentLabel: currentLabel,
|
||||||
}:
|
}:
|
||||||
@@ -278,7 +278,7 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// Translate.
|
// Translate.
|
||||||
translateFunc := func(value inputValue) (componentBuildResult[T], error) {
|
translateFunc := func(value componentInput) (componentBuildResult[T], error) {
|
||||||
var n T = new(N)
|
var n T = new(N)
|
||||||
currentLabel := value.currentLabel
|
currentLabel := value.currentLabel
|
||||||
node := value.node
|
node := value.node
|
||||||
@@ -311,7 +311,7 @@ func extractComponentValues[T low.Buildable[N], N any](label string, root *yaml.
|
|||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
err := datamodel.TranslatePipeline[inputValue, componentBuildResult[T]](in, out, translateFunc)
|
err := datamodel.TranslatePipeline[componentInput, componentBuildResult[T]](in, out, translateFunc)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return emptyResult, err
|
return emptyResult, err
|
||||||
|
|||||||
@@ -69,15 +69,15 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
|
|
||||||
// Translate YAML nodes to pathsMap using `TranslatePipeline`.
|
// Translate YAML nodes to pathsMap using `TranslatePipeline`.
|
||||||
type buildResult struct {
|
type buildResult struct {
|
||||||
k low.KeyReference[string]
|
key low.KeyReference[string]
|
||||||
v low.ValueReference[*PathItem]
|
value low.ValueReference[*PathItem]
|
||||||
}
|
}
|
||||||
type inputValue struct {
|
type buildInput struct {
|
||||||
currentNode *yaml.Node
|
currentNode *yaml.Node
|
||||||
pathNode *yaml.Node
|
pathNode *yaml.Node
|
||||||
}
|
}
|
||||||
pathsMap := make(map[low.KeyReference[string]]low.ValueReference[*PathItem])
|
pathsMap := make(map[low.KeyReference[string]]low.ValueReference[*PathItem])
|
||||||
in := make(chan inputValue)
|
in := make(chan buildInput)
|
||||||
out := make(chan buildResult)
|
out := make(chan buildResult)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -107,7 +107,7 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case in <- inputValue{
|
case in <- buildInput{
|
||||||
currentNode: currentNode,
|
currentNode: currentNode,
|
||||||
pathNode: pathNode,
|
pathNode: pathNode,
|
||||||
}:
|
}:
|
||||||
@@ -129,15 +129,15 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pathsMap[result.k] = result.v
|
pathsMap[result.key] = result.value
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err := datamodel.TranslatePipeline[inputValue, buildResult](in, out,
|
err := datamodel.TranslatePipeline[buildInput, buildResult](in, out,
|
||||||
func(value inputValue) (buildResult, error) {
|
func(value buildInput) (buildResult, error) {
|
||||||
pNode := value.pathNode
|
pNode := value.pathNode
|
||||||
cNode := value.currentNode
|
cNode := value.currentNode
|
||||||
|
|
||||||
@@ -170,11 +170,11 @@ func (p *Paths) Build(_, root *yaml.Node, idx *index.SpecIndex) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return buildResult{
|
return buildResult{
|
||||||
k: low.KeyReference[string]{
|
key: low.KeyReference[string]{
|
||||||
Value: cNode.Value,
|
Value: cNode.Value,
|
||||||
KeyNode: cNode,
|
KeyNode: cNode,
|
||||||
},
|
},
|
||||||
v: low.ValueReference[*PathItem]{
|
value: low.ValueReference[*PathItem]{
|
||||||
Value: path,
|
Value: path,
|
||||||
ValueNode: pNode,
|
ValueNode: pNode,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user