diff --git a/datamodel/high/node_builder.go b/datamodel/high/node_builder.go index a94425b..a7bc980 100644 --- a/datamodel/high/node_builder.go +++ b/datamodel/high/node_builder.go @@ -147,7 +147,6 @@ func (n *NodeBuilder) add(key string, i int) { // create a new node entry nodeEntry := &NodeEntry{Tag: tagName, Key: key} nodeEntry.RenderZero = renderZeroFlag - switch value.Kind() { case reflect.Float64, reflect.Float32: nodeEntry.Value = value.Float() diff --git a/datamodel/high/v3/document_test.go b/datamodel/high/v3/document_test.go index 0f6d507..fca6eff 100644 --- a/datamodel/high/v3/document_test.go +++ b/datamodel/high/v3/document_test.go @@ -292,8 +292,8 @@ func TestNewDocument_Components_SecuritySchemes(t *testing.T) { assert.Equal(t, "an oAuth security scheme", oAuth.Description) assert.Equal(t, 375, oAuth.GoLow().Description.ValueNode.Line) assert.Equal(t, 20, oAuth.GoLow().Description.ValueNode.Column) - assert.Equal(t, 2, orderedmap.Len(oAuth.Flows.Implicit.Scopes)) - assert.Equal(t, "read all burgers", oAuth.Flows.Implicit.Scopes.GetOrZero("read:burgers")) + assert.Equal(t, 2, len(oAuth.Flows.Implicit.Scopes)) + assert.Equal(t, "read all burgers", oAuth.Flows.Implicit.Scopes["read:burgers"]) assert.Equal(t, "https://pb33f.io/oauth", oAuth.Flows.AuthorizationCode.AuthorizationUrl) // check the lowness is low. diff --git a/datamodel/high/v3/oauth_flow.go b/datamodel/high/v3/oauth_flow.go index 316804d..3e77405 100644 --- a/datamodel/high/v3/oauth_flow.go +++ b/datamodel/high/v3/oauth_flow.go @@ -6,7 +6,6 @@ package v3 import ( "github.com/pb33f/libopenapi/datamodel/high" low "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/orderedmap" "gopkg.in/yaml.v3" ) @@ -16,7 +15,8 @@ type OAuthFlow struct { AuthorizationUrl string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"` TokenUrl string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"` RefreshUrl string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"` - Scopes orderedmap.Map[string, string] `json:"scopes,omitempty" yaml:"scopes,omitempty"` + // FIXME: Scopes must be converted to orderedmap.Map. Fix unmarshaling issue causing omitted `scopes` stanza on parsing. + Scopes map[string]string `json:"scopes,omitempty" yaml:"scopes,omitempty"` Extensions map[string]any `json:"-" yaml:"-"` low *low.OAuthFlow } @@ -28,9 +28,9 @@ func NewOAuthFlow(flow *low.OAuthFlow) *OAuthFlow { o.TokenUrl = flow.TokenUrl.Value o.AuthorizationUrl = flow.AuthorizationUrl.Value o.RefreshUrl = flow.RefreshUrl.Value - scopes := orderedmap.New[string, string]() - for pair := orderedmap.First(flow.Scopes.Value); pair != nil; pair = pair.Next() { - scopes.Set(pair.Key().Value, pair.Value().Value) + scopes := map[string]string{} + for k, v := range flow.Scopes.Value { + scopes[k.Value] = v.Value } o.Scopes = scopes o.Extensions = high.ExtractExtensions(flow.Extensions) diff --git a/datamodel/high/v3/oauth_flow_test.go b/datamodel/high/v3/oauth_flow_test.go index bd5dcf1..e63761c 100644 --- a/datamodel/high/v3/oauth_flow_test.go +++ b/datamodel/high/v3/oauth_flow_test.go @@ -7,7 +7,6 @@ import ( "strings" "testing" - "github.com/pb33f/libopenapi/orderedmap" "github.com/stretchr/testify/assert" ) @@ -17,10 +16,10 @@ func TestOAuthFlow_MarshalYAML(t *testing.T) { AuthorizationUrl: "https://pb33f.io", TokenUrl: "https://pb33f.io/token", RefreshUrl: "https://pb33f.io/refresh", - Scopes: orderedmap.ToOrderedMap(map[string]string{ + Scopes: map[string]string{ "chicken": "nuggets", "beefy": "soup", - }), + }, } rend, _ := oflow.Render() diff --git a/datamodel/high/v3/oauth_flows_test.go b/datamodel/high/v3/oauth_flows_test.go index ac5f16f..399909e 100644 --- a/datamodel/high/v3/oauth_flows_test.go +++ b/datamodel/high/v3/oauth_flows_test.go @@ -82,7 +82,7 @@ clientCredentials: CHIP:CHOP: microwave a sock` // now modify it and render it back out, and it should be identical! - r.ClientCredentials.Scopes.Set("CHIP:CHOP", "microwave a sock") + r.ClientCredentials.Scopes["CHIP:CHOP"] = "microwave a sock" rBytes, _ = r.Render() assert.Equal(t, modified, strings.TrimSpace(string(rBytes))) diff --git a/datamodel/low/v3/oauth_flows.go b/datamodel/low/v3/oauth_flows.go index 247a8a3..9692d68 100644 --- a/datamodel/low/v3/oauth_flows.go +++ b/datamodel/low/v3/oauth_flows.go @@ -11,7 +11,6 @@ import ( "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" ) @@ -97,7 +96,7 @@ type OAuthFlow struct { AuthorizationUrl low.NodeReference[string] TokenUrl low.NodeReference[string] RefreshUrl low.NodeReference[string] - Scopes low.NodeReference[orderedmap.Map[low.KeyReference[string], low.ValueReference[string]]] + Scopes low.NodeReference[map[low.KeyReference[string]]low.ValueReference[string]] Extensions map[low.KeyReference[string]]low.ValueReference[any] *low.Reference } @@ -109,7 +108,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.FindItemInOrderedMap[string](scope, o.Scopes.Value) + return low.FindItemInMap[string](scope, o.Scopes.Value) } // FindExtension attempts to locate an extension with a specified key @@ -136,10 +135,10 @@ func (o *OAuthFlow) Hash() [32]byte { if !o.RefreshUrl.IsEmpty() { f = append(f, o.RefreshUrl.Value) } - keys := make([]string, orderedmap.Len(o.Scopes.Value)) + keys := make([]string, len(o.Scopes.Value)) z := 0 - 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)))) + for k, v := range o.Scopes.Value { + keys[z] = fmt.Sprintf("%s-%s", k.Value, sha256.Sum256([]byte(fmt.Sprint(v.Value)))) z++ } sort.Strings(keys) diff --git a/what-changed/model/oauth_flows.go b/what-changed/model/oauth_flows.go index bb71edf..5c9345b 100644 --- a/what-changed/model/oauth_flows.go +++ b/what-changed/model/oauth_flows.go @@ -6,7 +6,6 @@ package model import ( "github.com/pb33f/libopenapi/datamodel/low" v3 "github.com/pb33f/libopenapi/datamodel/low/v3" - "github.com/pb33f/libopenapi/orderedmap" ) // OAuthFlowsChanges represents changes found between two OpenAPI OAuthFlows objects. @@ -229,26 +228,26 @@ func CompareOAuthFlow(l, r *v3.OAuthFlow) *OAuthFlowChanges { CheckProperties(props) - for pair := orderedmap.First(l.Scopes.Value); pair != nil; pair = pair.Next() { - if r != nil && r.FindScope(pair.Key().Value) == nil { + for k, v := range l.Scopes.Value { + if r != nil && r.FindScope(k.Value) == nil { CreateChange(&changes, ObjectRemoved, v3.Scopes, - pair.Value().ValueNode, nil, true, - pair.Key().Value, nil) + v.ValueNode, nil, true, + k.Value, nil) continue } - if r != nil && r.FindScope(pair.Key().Value) != nil { - if pair.Value().Value != r.FindScope(pair.Key().Value).Value { + if r != nil && r.FindScope(k.Value) != nil { + if v.Value != r.FindScope(k.Value).Value { CreateChange(&changes, Modified, v3.Scopes, - pair.Value().ValueNode, r.FindScope(pair.Key().Value).ValueNode, true, - pair.Value().Value, r.FindScope(pair.Key().Value).Value) + v.ValueNode, r.FindScope(k.Value).ValueNode, true, + v.Value, r.FindScope(k.Value).Value) } } } - for pair := orderedmap.First(r.Scopes.Value); pair != nil; pair = pair.Next() { - if l != nil && l.FindScope(pair.Key().Value) == nil { + for k, v := range r.Scopes.Value { + if l != nil && l.FindScope(k.Value) == nil { CreateChange(&changes, ObjectAdded, v3.Scopes, - nil, pair.Value().ValueNode, false, - nil, pair.Key().Value) + nil, v.ValueNode, false, + nil, k.Value) } } oa := new(OAuthFlowChanges)