mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 12:37:49 +00:00
lookups are performed inline now. keeps things simpler, however it has a performance knock, so it's time to refine async building were possible.
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package v3
|
|
|
|
import (
|
|
"github.com/pb33f/libopenapi/datamodel/low"
|
|
"github.com/pb33f/libopenapi/index"
|
|
"github.com/pb33f/libopenapi/utils"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
type Link struct {
|
|
OperationRef low.NodeReference[string]
|
|
OperationId low.NodeReference[string]
|
|
Parameters low.NodeReference[map[low.KeyReference[string]]low.ValueReference[string]]
|
|
RequestBody low.NodeReference[string]
|
|
Description low.NodeReference[string]
|
|
Server low.NodeReference[*Server]
|
|
Extensions map[low.KeyReference[string]]low.ValueReference[any]
|
|
}
|
|
|
|
func (l *Link) FindParameter(pName string) *low.ValueReference[string] {
|
|
return FindItemInMap[string](pName, l.Parameters.Value)
|
|
}
|
|
|
|
func (l *Link) Build(root *yaml.Node, idx *index.SpecIndex) error {
|
|
l.Extensions = ExtractExtensions(root)
|
|
|
|
// extract parameters
|
|
_, pl, pv := utils.FindKeyNodeFull(ParametersLabel, root.Content)
|
|
if pv != nil {
|
|
params := make(map[low.KeyReference[string]]low.ValueReference[string])
|
|
var currentParam *yaml.Node
|
|
for i, param := range pv.Content {
|
|
if i%2 == 0 {
|
|
currentParam = param
|
|
continue
|
|
}
|
|
params[low.KeyReference[string]{
|
|
Value: currentParam.Value,
|
|
KeyNode: currentParam,
|
|
}] = low.ValueReference[string]{
|
|
Value: param.Value,
|
|
ValueNode: param,
|
|
}
|
|
}
|
|
l.Parameters = low.NodeReference[map[low.KeyReference[string]]low.ValueReference[string]]{
|
|
Value: params,
|
|
KeyNode: pl,
|
|
ValueNode: pv,
|
|
}
|
|
}
|
|
return nil
|
|
}
|