77 "sort"
88 "strings"
99
10+ orderedmap "github.com/wk8/go-ordered-map/v2"
11+
1012 "github.com/getkin/kin-openapi/openapi2"
1113 "github.com/getkin/kin-openapi/openapi3"
1214)
@@ -66,16 +68,16 @@ func ToV3(doc2 *openapi2.T) (*openapi3.T, error) {
6668 }
6769 }
6870
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
7275 r , err := ToV3PathItem (doc2 , doc3 .Components , pathItem , doc2 .Consumes )
7376 if err != nil {
7477 return nil , err
7578 }
76- doc3Paths [ path ] = r
79+ doc3 . Paths . Set ( path , r )
7780 }
78- doc3 .Paths = doc3Paths
7981 }
8082
8183 if responses := doc2 .Responses ; len (responses ) != 0 {
@@ -540,9 +542,9 @@ func ToV3SecurityScheme(securityScheme *openapi2.SecurityScheme) (*openapi3.Secu
540542 result .Type = "oauth2"
541543 flows := & openapi3.OAuthFlows {}
542544 result .Flows = flows
543- scopesMap := make ( map [string ] string )
545+ scopesMap := orderedmap. New [string , string ]( len ( securityScheme . Scopes ) )
544546 for scope , desc := range securityScheme .Scopes {
545- scopesMap [ scope ] = desc
547+ scopesMap . Set ( scope , desc )
546548 }
547549 flow := & openapi3.OAuthFlow {
548550 AuthorizationURL : securityScheme .AuthorizationURL ,
@@ -611,7 +613,8 @@ func FromV3(doc3 *openapi3.T) (*openapi2.T, error) {
611613 if isHTTP {
612614 doc2 .Schemes = append (doc2 .Schemes , "http" )
613615 }
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
615618 if pathItem == nil {
616619 continue
617620 }
@@ -636,7 +639,7 @@ func FromV3(doc3 *openapi3.T) (*openapi2.T, error) {
636639 params = append (params , p )
637640 }
638641 sort .Sort (params )
639- doc2 .Paths [ path ] .Parameters = params
642+ doc2 .Paths . Value ( path ) .Parameters = params
640643 }
641644
642645 for name , param := range doc3 .Components .Parameters {
@@ -1155,9 +1158,9 @@ func FromV3SecurityScheme(doc3 *openapi3.T, ref *openapi3.SecuritySchemeRef) (*o
11551158 return nil , nil
11561159 }
11571160
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
11611164 }
11621165 }
11631166 default :
@@ -1183,12 +1186,12 @@ func stripNonExtensions(extensions map[string]interface{}) map[string]interface{
11831186
11841187func addPathExtensions (doc2 * openapi2.T , path string , extensions map [string ]interface {}) {
11851188 if doc2 .Paths == nil {
1186- doc2 .Paths = make ( map [ string ] * openapi2.PathItem )
1189+ doc2 .Paths = openapi2 .NewPaths ( )
11871190 }
1188- pathItem := doc2 .Paths [ path ]
1191+ pathItem := doc2 .Paths . Value ( path )
11891192 if pathItem == nil {
11901193 pathItem = & openapi2.PathItem {}
1191- doc2 .Paths [ path ] = pathItem
1194+ doc2 .Paths . Set ( path , pathItem )
11921195 }
11931196 pathItem .Extensions = extensions
11941197}
0 commit comments