Fixed a low level bug with locating nodes.

locating nodes was looking through two levels to locate something. This is not the correct behavior, after making the change - lots of tests needed to be updated to be correct in what they put into as a the root node.
This commit is contained in:
Dave Shanley
2022-11-04 09:50:20 -04:00
parent 131513a6f6
commit a184c5e909
34 changed files with 220 additions and 161 deletions

View File

@@ -4,11 +4,13 @@
package v3
import (
"crypto/sha256"
"fmt"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
"sort"
"strings"
)
@@ -122,3 +124,25 @@ func (p *Paths) Build(root *yaml.Node, idx *index.SpecIndex) error {
p.PathItems = pathsMap
return nil
}
// Hash will return a consistent SHA256 Hash of the PathItem object
func (p *Paths) Hash() [32]byte {
var f []string
l := make([]string, len(p.PathItems))
keys := make(map[string]low.ValueReference[*PathItem])
z := 0
for k := range p.PathItems {
keys[k.Value] = p.PathItems[k]
l[z] = k.Value
z++
}
sort.Strings(l)
for k := range l {
f = append(f, low.GenerateHashString(keys[l[k]].Value))
}
for k := range p.Extensions {
f = append(f, fmt.Sprintf("%s-%x", k.Value,
sha256.Sum256([]byte(fmt.Sprint(p.Extensions[k].Value)))))
}
return sha256.Sum256([]byte(strings.Join(f, "|")))
}