8
8
"sort"
9
9
"strings"
10
10
11
+ orderedmap "github.com/wk8/go-ordered-map/v2"
12
+
11
13
"github.com/getkin/kin-openapi/openapi2"
12
14
"github.com/getkin/kin-openapi/openapi3"
13
15
)
@@ -69,16 +71,16 @@ func ToV3(doc2 *openapi2.T) (*openapi3.T, error) {
69
71
}
70
72
}
71
73
72
- if paths := doc2 .Paths ; len (paths ) != 0 {
73
- doc3Paths := make (map [string ]* openapi3.PathItem , len (paths ))
74
- for path , pathItem := range paths {
74
+ if paths := doc2 .Paths ; paths .Len () != 0 {
75
+ doc3 .Paths = openapi3 .NewPathsWithCapacity (paths .Len ())
76
+ for pair := paths .Iter (); pair != nil ; pair = pair .Next () {
77
+ path , pathItem := pair .Key , pair .Value
75
78
r , err := ToV3PathItem (doc2 , & doc3 .Components , pathItem , doc2 .Consumes )
76
79
if err != nil {
77
80
return nil , err
78
81
}
79
- doc3Paths [ path ] = r
82
+ doc3 . Paths . Set ( path , r )
80
83
}
81
- doc3 .Paths = doc3Paths
82
84
}
83
85
84
86
if responses := doc2 .Responses ; len (responses ) != 0 {
@@ -556,9 +558,9 @@ func ToV3SecurityScheme(securityScheme *openapi2.SecurityScheme) (*openapi3.Secu
556
558
result .Type = "oauth2"
557
559
flows := & openapi3.OAuthFlows {}
558
560
result .Flows = flows
559
- scopesMap := make ( map [string ] string )
561
+ scopesMap := orderedmap. New [string , string ]( len ( securityScheme . Scopes ) )
560
562
for scope , desc := range securityScheme .Scopes {
561
- scopesMap [ scope ] = desc
563
+ scopesMap . Set ( scope , desc )
562
564
}
563
565
flow := & openapi3.OAuthFlow {
564
566
AuthorizationURL : securityScheme .AuthorizationURL ,
@@ -628,7 +630,8 @@ func FromV3(doc3 *openapi3.T) (*openapi2.T, error) {
628
630
if isHTTP {
629
631
doc2 .Schemes = append (doc2 .Schemes , "http" )
630
632
}
631
- for path , pathItem := range doc3 .Paths {
633
+ for pair := doc3 .Paths .Iter (); pair != nil ; pair = pair .Next () {
634
+ path , pathItem := pair .Key , pair .Value
632
635
if pathItem == nil {
633
636
continue
634
637
}
@@ -654,7 +657,7 @@ func FromV3(doc3 *openapi3.T) (*openapi2.T, error) {
654
657
params = append (params , p )
655
658
}
656
659
sort .Sort (params )
657
- doc2 .Paths [ path ] .Parameters = params
660
+ doc2 .Paths . Value ( path ) .Parameters = params
658
661
}
659
662
660
663
for name , param := range doc3 .Components .Parameters {
@@ -1179,9 +1182,9 @@ func FromV3SecurityScheme(doc3 *openapi3.T, ref *openapi3.SecuritySchemeRef) (*o
1179
1182
return nil , nil
1180
1183
}
1181
1184
1182
- result .Scopes = make (map [string ]string , len ( flow .Scopes ))
1183
- for scope , desc := range flow .Scopes {
1184
- result .Scopes [scope ] = desc
1185
+ result .Scopes = make (map [string ]string , flow .Scopes . Len ( ))
1186
+ for pair := flow .Scopes . Oldest (); pair != nil ; pair = pair . Next () {
1187
+ result .Scopes [pair . Key ] = pair . Value
1185
1188
}
1186
1189
}
1187
1190
default :
@@ -1205,12 +1208,12 @@ func stripNonCustomExtensions(extensions map[string]interface{}) {
1205
1208
1206
1209
func addPathExtensions (doc2 * openapi2.T , path string , extensionProps openapi3.ExtensionProps ) {
1207
1210
if doc2 .Paths == nil {
1208
- doc2 .Paths = make ( map [ string ] * openapi2.PathItem )
1211
+ doc2 .Paths = openapi2 .NewPaths ( )
1209
1212
}
1210
- pathItem := doc2 .Paths [ path ]
1213
+ pathItem := doc2 .Paths . Value ( path )
1211
1214
if pathItem == nil {
1212
1215
pathItem = & openapi2.PathItem {}
1213
- doc2 .Paths [ path ] = pathItem
1216
+ doc2 .Paths . Set ( path , pathItem )
1214
1217
}
1215
1218
pathItem .ExtensionProps = extensionProps
1216
1219
}
0 commit comments