mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
Added hash functions to various low level models.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package v3
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"github.com/pb33f/libopenapi/datamodel/low"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ServerVariable represents a low-level OpenAPI 3+ ServerVariable object.
|
||||
@@ -16,3 +18,18 @@ type ServerVariable struct {
|
||||
Default low.NodeReference[string]
|
||||
Description low.NodeReference[string]
|
||||
}
|
||||
|
||||
// Hash will return a consistent SHA256 Hash of the ServerVariable object
|
||||
func (s *ServerVariable) Hash() [32]byte {
|
||||
var f []string
|
||||
for k := range s.Enum {
|
||||
f = append(f, s.Enum[k].Value)
|
||||
}
|
||||
if !s.Default.IsEmpty() {
|
||||
f = append(f, s.Default.Value)
|
||||
}
|
||||
if !s.Description.IsEmpty() {
|
||||
f = append(f, s.Description.Value)
|
||||
}
|
||||
return sha256.Sum256([]byte(strings.Join(f, "|")))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user