7
7
"sort"
8
8
"strings"
9
9
10
+ orderedmap "github.com/wk8/go-ordered-map/v2"
11
+
10
12
"github.com/getkin/kin-openapi/openapi2"
11
13
"github.com/getkin/kin-openapi/openapi3"
12
14
)
@@ -66,16 +68,16 @@ func ToV3(doc2 *openapi2.T) (*openapi3.T, error) {
66
68
}
67
69
}
68
70
69
- if paths := doc2 .Paths ; len (paths ) != 0 {
70
- doc3Paths := make (map [string ]* openapi3.PathItem , len (paths ))
71
- for path , pathItem := range paths {
71
+ if paths := doc2 .Paths ; paths .Len () != 0 {
72
+ doc3 .Paths = openapi3 .NewPathsWithCapacity (paths .Len ())
73
+ for pair := paths .Iter (); pair != nil ; pair = pair .Next () {
74
+ path , pathItem := pair .Key , pair .Value
72
75
r , err := ToV3PathItem (doc2 , doc3 .Components , pathItem , doc2 .Consumes )
73
76
if err != nil {
74
77
return nil , err
75
78
}
76
- doc3Paths [ path ] = r
79
+ doc3 . Paths . Set ( path , r )
77
80
}
78
- doc3 .Paths = doc3Paths
79
81
}
80
82
81
83
if responses := doc2 .Responses ; len (responses ) != 0 {
@@ -540,9 +542,9 @@ func ToV3SecurityScheme(securityScheme *openapi2.SecurityScheme) (*openapi3.Secu
540
542
result .Type = "oauth2"
541
543
flows := & openapi3.OAuthFlows {}
542
544
result .Flows = flows
543
- scopesMap := make ( map [string ] string )
545
+ scopesMap := orderedmap. New [string , string ]( len ( securityScheme . Scopes ) )
544
546
for scope , desc := range securityScheme .Scopes {
545
- scopesMap [ scope ] = desc
547
+ scopesMap . Set ( scope , desc )
546
548
}
547
549
flow := & openapi3.OAuthFlow {
548
550
AuthorizationURL : securityScheme .AuthorizationURL ,
@@ -611,7 +613,8 @@ func FromV3(doc3 *openapi3.T) (*openapi2.T, error) {
611
613
if isHTTP {
612
614
doc2 .Schemes = append (doc2 .Schemes , "http" )
613
615
}
614
- for path , pathItem := range doc3 .Paths {
616
+ for pair := doc3 .Paths .Iter (); pair != nil ; pair = pair .Next () {
617
+ path , pathItem := pair .Key , pair .Value
615
618
if pathItem == nil {
616
619
continue
617
620
}
@@ -636,7 +639,7 @@ func FromV3(doc3 *openapi3.T) (*openapi2.T, error) {
636
639
params = append (params , p )
637
640
}
638
641
sort .Sort (params )
639
- doc2 .Paths [ path ] .Parameters = params
642
+ doc2 .Paths . Value ( path ) .Parameters = params
640
643
}
641
644
642
645
for name , param := range doc3 .Components .Parameters {
@@ -1155,9 +1158,9 @@ func FromV3SecurityScheme(doc3 *openapi3.T, ref *openapi3.SecuritySchemeRef) (*o
1155
1158
return nil , nil
1156
1159
}
1157
1160
1158
- result .Scopes = make (map [string ]string , len ( flow .Scopes ))
1159
- for scope , desc := range flow .Scopes {
1160
- result .Scopes [scope ] = desc
1161
+ result .Scopes = make (map [string ]string , flow .Scopes . Len ( ))
1162
+ for pair := flow .Scopes . Oldest (); pair != nil ; pair = pair . Next () {
1163
+ result .Scopes [pair . Key ] = pair . Value
1161
1164
}
1162
1165
}
1163
1166
default :
@@ -1183,12 +1186,12 @@ func stripNonExtensions(extensions map[string]interface{}) map[string]interface{
1183
1186
1184
1187
func addPathExtensions (doc2 * openapi2.T , path string , extensions map [string ]interface {}) {
1185
1188
if doc2 .Paths == nil {
1186
- doc2 .Paths = make ( map [ string ] * openapi2.PathItem )
1189
+ doc2 .Paths = openapi2 .NewPaths ( )
1187
1190
}
1188
- pathItem := doc2 .Paths [ path ]
1191
+ pathItem := doc2 .Paths . Value ( path )
1189
1192
if pathItem == nil {
1190
1193
pathItem = & openapi2.PathItem {}
1191
- doc2 .Paths [ path ] = pathItem
1194
+ doc2 .Paths . Set ( path , pathItem )
1192
1195
}
1193
1196
pathItem .Extensions = extensions
1194
1197
}
0 commit comments