@@ -11,31 +11,34 @@ import (
1111)
1212
1313func (p * parser ) parseSecurityScheme (
14- s * ogen.SecurityScheme ,
14+ scheme * ogen.SecurityScheme ,
1515 scopes []string ,
1616 ctx * resolveCtx ,
17- ) (* ogen.SecurityScheme , error ) {
18- if s == nil {
17+ ) (_ * ogen.SecurityScheme , rerr error ) {
18+ if scheme == nil {
1919 return nil , errors .New ("securityScheme is empty or null" )
2020 }
2121
22- if ref := s .Ref ; ref != "" {
22+ if ref := scheme .Ref ; ref != "" {
2323 sch , err := p .resolveSecurityScheme (ref , ctx )
2424 if err != nil {
2525 return nil , errors .Wrap (err , "resolve security schema" )
2626 }
2727 return sch , nil
2828 }
29+ defer func () {
30+ rerr = p .wrapLocation (scheme , rerr )
31+ }()
2932
3033 if err := func () error {
31- switch s .Type {
34+ switch scheme .Type {
3235 case "apiKey" :
33- switch s .In {
36+ switch scheme .In {
3437 case "query" , "header" , "cookie" :
3538 default :
36- return errors .Errorf (`invalid "in": %q` , s .In )
39+ return errors .Errorf (`invalid "in": %q` , scheme .In )
3740 }
38- if s .Name == "" {
41+ if scheme .Name == "" {
3942 return errors .New (`"name" is required and MUST be a non-empty string` )
4043 }
4144 return nil
@@ -45,7 +48,7 @@ func (p *parser) parseSecurityScheme(
4548 // Probably such validation is too strict.
4649
4750 // Values from https://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml.
48- switch strings .ToLower (s .Scheme ) {
51+ switch strings .ToLower (scheme .Scheme ) {
4952 case "basic" ,
5053 "bearer" ,
5154 "digest" ,
@@ -57,26 +60,26 @@ func (p *parser) parseSecurityScheme(
5760 "scram-sha-256" ,
5861 "vapid" :
5962 default :
60- return errors .Errorf (`invalid "scheme": %q` , s .Scheme )
63+ return errors .Errorf (`invalid "scheme": %q` , scheme .Scheme )
6164 }
6265 return nil
6366 case "mutualTLS" :
6467 return nil
6568 case "oauth2" :
66- return validateOAuthFlows (scopes , s .Flows )
69+ return validateOAuthFlows (scopes , scheme .Flows )
6770 case "openIdConnect" :
68- if _ , err := url .ParseRequestURI (s .OpenIDConnectURL ); err != nil {
71+ if _ , err := url .ParseRequestURI (scheme .OpenIDConnectURL ); err != nil {
6972 return errors .Wrap (err , `"openIdConnectUrl" MUST be in the form of a URL` )
7073 }
7174 return nil
7275 default :
73- return errors .Errorf ("unknown security scheme type %q" , s .Type )
76+ return errors .Errorf ("unknown security scheme type %q" , scheme .Type )
7477 }
7578 }(); err != nil {
76- return nil , errors .Wrap (err , s .Type )
79+ return nil , errors .Wrap (err , scheme .Type )
7780 }
7881
79- return s , nil
82+ return scheme , nil
8083}
8184
8285func validateOAuthFlows (scopes []string , flows * ogen.OAuthFlows ) error {
0 commit comments