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)
@@ -69,16 +71,16 @@ func ToV3(doc2 *openapi2.T) (*openapi3.T, error) {
6971 }
7072 }
7173
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
7578 r , err := ToV3PathItem (doc2 , & doc3 .Components , pathItem , doc2 .Consumes )
7679 if err != nil {
7780 return nil , err
7881 }
79- doc3Paths [ path ] = r
82+ doc3 . Paths . Set ( path , r )
8083 }
81- doc3 .Paths = doc3Paths
8284 }
8385
8486 if responses := doc2 .Responses ; len (responses ) != 0 {
@@ -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 ]( len ( securityScheme . Scopes ) )
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 ,
@@ -628,7 +630,8 @@ func FromV3(doc3 *openapi3.T) (*openapi2.T, error) {
628630 if isHTTP {
629631 doc2 .Schemes = append (doc2 .Schemes , "http" )
630632 }
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
632635 if pathItem == nil {
633636 continue
634637 }
@@ -654,7 +657,7 @@ func FromV3(doc3 *openapi3.T) (*openapi2.T, error) {
654657 params = append (params , p )
655658 }
656659 sort .Sort (params )
657- doc2 .Paths [ path ] .Parameters = params
660+ doc2 .Paths . Value ( path ) .Parameters = params
658661 }
659662
660663 for name , param := range doc3 .Components .Parameters {
@@ -1179,9 +1182,9 @@ func FromV3SecurityScheme(doc3 *openapi3.T, ref *openapi3.SecuritySchemeRef) (*o
11791182 return nil , nil
11801183 }
11811184
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
11851188 }
11861189 }
11871190 default :
@@ -1205,12 +1208,12 @@ func stripNonCustomExtensions(extensions map[string]interface{}) {
12051208
12061209func addPathExtensions (doc2 * openapi2.T , path string , extensionProps openapi3.ExtensionProps ) {
12071210 if doc2 .Paths == nil {
1208- doc2 .Paths = make ( map [ string ] * openapi2.PathItem )
1211+ doc2 .Paths = openapi2 .NewPaths ( )
12091212 }
1210- pathItem := doc2 .Paths [ path ]
1213+ pathItem := doc2 .Paths . Value ( path )
12111214 if pathItem == nil {
12121215 pathItem = & openapi2.PathItem {}
1213- doc2 .Paths [ path ] = pathItem
1216+ doc2 .Paths . Set ( path , pathItem )
12141217 }
12151218 pathItem .ExtensionProps = extensionProps
12161219}
0 commit comments