Refactored version directory names

3.0 and 2.0 do not work, there are multiple versions and anything with a period in it sucks from my point of view, v2 and v3 feel much better from a DX perspective.
This commit is contained in:
Dave Shanley
2022-09-16 08:33:39 -04:00
parent 849074d0bc
commit 3d5ecf0efb
104 changed files with 48 additions and 48 deletions

View File

@@ -0,0 +1,71 @@
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package v2
import (
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index"
"gopkg.in/yaml.v3"
)
const (
ExamplesLabel = "examples"
)
type Examples struct {
Values map[low.KeyReference[string]]low.ValueReference[any]
}
func (e *Examples) FindExample(name string) *low.ValueReference[any] {
return low.FindItemInMap[any](name, e.Values)
}
func (e *Examples) Build(root *yaml.Node, _ *index.SpecIndex) error {
var keyNode, currNode *yaml.Node
var err error
e.Values = make(map[low.KeyReference[string]]low.ValueReference[any])
for i := range root.Content {
if i%2 == 0 {
keyNode = root.Content[i]
continue
}
currNode = root.Content[i]
var n map[string]interface{}
err = currNode.Decode(&n)
if err != nil {
var k []interface{}
err = currNode.Decode(&k)
if err != nil {
// lets just default to interface
var j interface{}
_ = currNode.Decode(&j)
e.Values[low.KeyReference[string]{
Value: keyNode.Value,
KeyNode: keyNode,
}] = low.ValueReference[any]{
Value: j,
ValueNode: currNode,
}
continue
}
e.Values[low.KeyReference[string]{
Value: keyNode.Value,
KeyNode: keyNode,
}] = low.ValueReference[any]{
Value: k,
ValueNode: currNode,
}
continue
}
e.Values[low.KeyReference[string]{
Value: keyNode.Value,
KeyNode: keyNode,
}] = low.ValueReference[any]{
Value: n,
ValueNode: currNode,
}
}
return nil
}