mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
48 lines
951 B
Go
48 lines
951 B
Go
package v3
|
|
|
|
import (
|
|
"github.com/pb33f/libopenapi/datamodel/low"
|
|
"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) error {
|
|
// extract extensions
|
|
extensionMap, err := ExtractExtensions(root)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
ex.Extensions = extensionMap
|
|
|
|
// 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
|
|
}
|