Files
libopenapi/datamodel/low/3.0/example.go
Dave Shanley 248b4daa80 We-worked model to remove resolver.
lookups are performed inline now. keeps things simpler, however it has a performance knock, so it's time to refine async building were possible.
2022-08-11 14:54:25 -04:00

44 lines
920 B
Go

package v3
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
)
const (
ExamplesLabel = "examples"
ExampleLabel = "example"
ValueLabel = "value"
)
type Example struct {
Summary low.NodeReference[string]
Description low.NodeReference[string]
Value low.NodeReference[any]
ExternalValue low.NodeReference[string]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
}
func (ex *Example) Build(root *yaml.Node, idx *index.SpecIndex) error {
ex.Extensions = ExtractExtensions(root)
// extract value
_, ln, vn := utils.FindKeyNodeFull(ValueLabel, root.Content)
if vn != nil {
var n map[string]interface{}
err := vn.Decode(&n)
if err != nil {
return err
}
ex.Value = low.NodeReference[any]{
Value: n,
KeyNode: ln,
ValueNode: vn,
}
}
return nil
}