mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 04:20:14 +00:00
Working through what changed rabbit hole
Parameter dependencies mean we're back in the ball of yarn stage. Coverage is going to drop for a bit, until all the new hashing and interfaces are in place.
This commit is contained in:
@@ -4,11 +4,14 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"github.com/pb33f/libopenapi/index"
|
||||
"github.com/pb33f/libopenapi/utils"
|
||||
"gopkg.in/yaml.v3"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Example represents a low-level Example object as defined by OpenAPI 3+
|
||||
@@ -26,6 +29,28 @@ func (ex *Example) FindExtension(ext string) *low.ValueReference[any] {
|
||||
return low.FindItemInMap[any](ext, ex.Extensions)
|
||||
}
|
||||
|
||||
// Hash will return a consistent SHA256 Hash of the Discriminator object
|
||||
func (ex *Example) Hash() [32]byte {
|
||||
var f []string
|
||||
if ex.Summary.Value != "" {
|
||||
f = append(f, ex.Summary.Value)
|
||||
}
|
||||
if ex.Description.Value != "" {
|
||||
f = append(f, ex.Description.Value)
|
||||
}
|
||||
if ex.Value.Value != "" {
|
||||
// this could be anything!
|
||||
f = append(f, fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprint(ex.Value.Value)))))
|
||||
}
|
||||
if ex.ExternalValue.Value != "" {
|
||||
f = append(f, ex.ExternalValue.Value)
|
||||
}
|
||||
for k := range ex.Extensions {
|
||||
f = append(f, fmt.Sprintf("%s-%x", k.Value, sha256.Sum256([]byte(fmt.Sprint(ex.Extensions[k].Value)))))
|
||||
}
|
||||
return sha256.Sum256([]byte(strings.Join(f, "|")))
|
||||
}
|
||||
|
||||
// Build extracts extensions and example value
|
||||
func (ex *Example) Build(root *yaml.Node, idx *index.SpecIndex) error {
|
||||
ex.Extensions = low.ExtractExtensions(root)
|
||||
|
||||
Reference in New Issue
Block a user