Monster refactor of map to orderedmap.Map data type.

This commit is contained in:
Shawn Poulson
2023-08-30 13:12:03 -04:00
parent 652e818456
commit f389fedadd
91 changed files with 1264 additions and 1192 deletions

View File

@@ -6,12 +6,14 @@ 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"
"github.com/pb33f/libopenapi/datamodel/low"
"github.com/pb33f/libopenapi/index"
"github.com/pb33f/libopenapi/orderedmap"
"github.com/pb33f/libopenapi/utils"
"gopkg.in/yaml.v3"
)
// OAuthFlows represents a low-level OpenAPI 3+ OAuthFlows object.
@@ -95,7 +97,7 @@ type OAuthFlow struct {
AuthorizationUrl low.NodeReference[string]
TokenUrl low.NodeReference[string]
RefreshUrl low.NodeReference[string]
Scopes low.NodeReference[map[low.KeyReference[string]]low.ValueReference[string]]
Scopes low.NodeReference[orderedmap.Map[low.KeyReference[string], low.ValueReference[string]]]
Extensions map[low.KeyReference[string]]low.ValueReference[any]
*low.Reference
}
@@ -107,7 +109,7 @@ func (o *OAuthFlow) GetExtensions() map[low.KeyReference[string]]low.ValueRefere
// FindScope attempts to locate a scope using a specified name.
func (o *OAuthFlow) FindScope(scope string) *low.ValueReference[string] {
return low.FindItemInMap[string](scope, o.Scopes.Value)
return low.FindItemInOrderedMap[string](scope, o.Scopes.Value)
}
// FindExtension attempts to locate an extension with a specified key
@@ -134,10 +136,10 @@ func (o *OAuthFlow) Hash() [32]byte {
if !o.RefreshUrl.IsEmpty() {
f = append(f, o.RefreshUrl.Value)
}
keys := make([]string, len(o.Scopes.Value))
keys := make([]string, orderedmap.Len(o.Scopes.Value))
z := 0
for k := range o.Scopes.Value {
keys[z] = fmt.Sprintf("%s-%s", k.Value, sha256.Sum256([]byte(fmt.Sprint(o.Scopes.Value[k].Value))))
for pair := orderedmap.First(o.Scopes.Value); pair != nil; pair = pair.Next() {
keys[z] = fmt.Sprintf("%s-%s", pair.Key().Value, sha256.Sum256([]byte(fmt.Sprint(pair.Value().Value))))
z++
}
sort.Strings(keys)