Skip to content

Commit 7b9dca8

Browse files
committed
WIP needs un/marshalling
Signed-off-by: Pierre Fenoll <pierrefenoll@gmail.com>
1 parent b4b41f3 commit 7b9dca8

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

go.mod

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
module github.com/getkin/kin-openapi
22

3-
go 1.16
3+
go 1.18
44

55
require (
66
github.com/go-openapi/jsonpointer v0.19.5
77
github.com/gorilla/mux v1.8.0
88
github.com/invopop/yaml v0.1.0
99
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
1010
github.com/stretchr/testify v1.8.1
11-
gopkg.in/yaml.v2 v2.4.0 // indirect
11+
github.com/wk8/go-ordered-map/v2 v2.0.0
1212
gopkg.in/yaml.v3 v3.0.1
1313
)
14+
15+
require (
16+
github.com/bahlo/generic-list-go v0.2.0 // indirect
17+
github.com/davecgh/go-spew v1.1.1 // indirect
18+
github.com/go-openapi/swag v0.19.5 // indirect
19+
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e // indirect
20+
github.com/pmezard/go-difflib v1.0.0 // indirect
21+
gopkg.in/yaml.v2 v2.4.0 // indirect
22+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
2+
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
13
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
24
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
35
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -29,6 +31,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
2931
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
3032
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
3133
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
34+
github.com/wk8/go-ordered-map/v2 v2.0.0 h1:jWOAU/F5AkYb8jr/rkVPe418g7nf2CZBzyfOR4Y7Q1w=
35+
github.com/wk8/go-ordered-map/v2 v2.0.0/go.mod h1:fGIuB3GmY3JZP6L3t5riKtaSH9u13IYVYvar5Ee+9lM=
3236
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3337
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
3438
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

openapi2conv/openapi2_conv.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"sort"
99
"strings"
1010

11+
orderedmap "github.com/wk8/go-ordered-map/v2"
12+
1113
"github.com/getkin/kin-openapi/openapi2"
1214
"github.com/getkin/kin-openapi/openapi3"
1315
)
@@ -556,9 +558,9 @@ func ToV3SecurityScheme(securityScheme *openapi2.SecurityScheme) (*openapi3.Secu
556558
result.Type = "oauth2"
557559
flows := &openapi3.OAuthFlows{}
558560
result.Flows = flows
559-
scopesMap := make(map[string]string)
561+
scopesMap := orderedmap.New[string, string]()
560562
for scope, desc := range securityScheme.Scopes {
561-
scopesMap[scope] = desc
563+
scopesMap.Set(scope, desc)
562564
}
563565
flow := &openapi3.OAuthFlow{
564566
AuthorizationURL: securityScheme.AuthorizationURL,
@@ -1179,9 +1181,9 @@ func FromV3SecurityScheme(doc3 *openapi3.T, ref *openapi3.SecuritySchemeRef) (*o
11791181
return nil, nil
11801182
}
11811183

1182-
result.Scopes = make(map[string]string, len(flow.Scopes))
1183-
for scope, desc := range flow.Scopes {
1184-
result.Scopes[scope] = desc
1184+
result.Scopes = make(map[string]string, flow.Scopes.Len())
1185+
for pair := flow.Scopes.Oldest(); pair != nil; pair = pair.Next() {
1186+
result.Scopes[pair.Key] = pair.Value
11851187
}
11861188
}
11871189
default:

openapi3/security_scheme.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/url"
88

99
"github.com/go-openapi/jsonpointer"
10+
orderedmap "github.com/wk8/go-ordered-map/v2"
1011

1112
"github.com/getkin/kin-openapi/jsoninfo"
1213
)
@@ -238,10 +239,10 @@ func (flows *OAuthFlows) Validate(ctx context.Context, opts ...ValidationOption)
238239
type OAuthFlow struct {
239240
ExtensionProps `json:"-" yaml:"-"`
240241

241-
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
242-
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
243-
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
244-
Scopes map[string]string `json:"scopes" yaml:"scopes"`
242+
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
243+
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
244+
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
245+
Scopes *orderedmap.OrderedMap[string, string] `json:"scopes" yaml:"scopes"`
245246
}
246247

247248
// MarshalJSON returns the JSON encoding of OAuthFlow.
@@ -264,7 +265,7 @@ func (flow *OAuthFlow) Validate(ctx context.Context, opts ...ValidationOption) e
264265
}
265266
}
266267

267-
if v := flow.Scopes; len(v) == 0 {
268+
if v := flow.Scopes; v.Len() == 0 {
268269
return errors.New("field 'scopes' is empty or missing")
269270
}
270271

0 commit comments

Comments
 (0)