v3 Links, callbacks operations low level models at 100% coverage

This commit is contained in:
Dave Shanley
2022-11-09 09:26:23 -05:00
parent 4ca8e160ed
commit aa62232440
7 changed files with 172 additions and 24 deletions

View File

@@ -4,9 +4,12 @@
package v3
import (
"crypto/sha256"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index"
"gopkg.in/yaml.v3"
"sort"
"strings"
)
// Callback represents a low-level Callback object for OpenAPI 3+.
@@ -59,3 +62,18 @@ func (cb *Callback) Build(root *yaml.Node, idx *index.SpecIndex) error {
}
return nil
}
// Hash will return a consistent SHA256 Hash of the Callback object
func (cb *Callback) Hash() [32]byte {
var f []string
var keys []string
keys = make([]string, len(cb.Expression.Value))
z := 0
for k := range cb.Expression.Value {
keys[z] = low.GenerateHashString(cb.Expression.Value[k].Value)
z++
}
sort.Strings(keys)
f = append(f, keys...)
return sha256.Sum256([]byte(strings.Join(f, "|")))
}