@@ -61,10 +61,17 @@ function parseSecurityClass(
6161 const securityDecorator : SecurityDecorator =
6262 parseSecurityDecorator ( securityAnn ) ;
6363 if ( securityDecorator == null ) return ;
64+
65+ const value = security [ fname ] ;
66+
6467 if ( securityDecorator . Option ) {
65- return parseSecurityOption ( client , security [ fname ] ) ;
68+ return parseSecurityOption ( client , value ) ;
6669 } else if ( securityDecorator . Scheme ) {
67- return parseSecurityScheme ( client , securityDecorator , security [ fname ] ) ;
70+ if ( securityDecorator . SubType === "basic" && value !== Object ( value ) ) {
71+ return parseSecurityScheme ( client , securityDecorator , security ) ;
72+ } else {
73+ client = parseSecurityScheme ( client , securityDecorator , value ) ;
74+ }
6875 }
6976 } ) ;
7077
@@ -85,10 +92,8 @@ function parseSecurityOption(
8592 if ( securityAnn == null ) return ;
8693 const securityDecorator : SecurityDecorator =
8794 parseSecurityDecorator ( securityAnn ) ;
88- if ( securityDecorator != null && securityDecorator . Scheme ) return ;
89- if ( securityDecorator . Scheme ) {
90- return parseSecurityScheme ( client , securityDecorator , optionType [ fname ] ) ;
91- }
95+ if ( securityDecorator == null || ! securityDecorator . Scheme ) return ;
96+ return parseSecurityScheme ( client , securityDecorator , optionType [ fname ] ) ;
9297 } ) ;
9398
9499 return client ;
@@ -99,65 +104,91 @@ function parseSecurityScheme(
99104 schemeDecorator : SecurityDecorator ,
100105 scheme : any
101106) : AxiosInstance {
102- if ( schemeDecorator . Type === "http" && schemeDecorator . SubType === "basic" ) {
103- return parseBasicAuthScheme ( client , scheme ) ;
104- }
107+ if ( scheme === Object ( scheme ) ) {
108+ if (
109+ schemeDecorator . Type === "http" &&
110+ schemeDecorator . SubType === "basic"
111+ ) {
112+ return parseBasicAuthScheme ( client , scheme ) ;
113+ }
105114
106- const fieldNames : string [ ] = Object . getOwnPropertyNames ( scheme ) ;
107- fieldNames . forEach ( ( fname ) => {
108- const securityAnn : string = Reflect . getMetadata (
109- securityMetadataKey ,
110- scheme ,
111- fname
115+ const fieldNames : string [ ] = Object . getOwnPropertyNames ( scheme ) ;
116+ fieldNames . forEach ( ( fname ) => {
117+ const securityAnn : string = Reflect . getMetadata (
118+ securityMetadataKey ,
119+ scheme ,
120+ fname
121+ ) ;
122+ if ( securityAnn == null ) return ;
123+ const securityDecorator : SecurityDecorator =
124+ parseSecurityDecorator ( securityAnn ) ;
125+ if ( securityDecorator == null || securityDecorator . Name === "" ) return ;
126+
127+ client = parseSecuritySchemeValue (
128+ client ,
129+ schemeDecorator ,
130+ securityDecorator ,
131+ scheme [ fname ]
132+ ) ;
133+ } ) ;
134+ } else {
135+ client = parseSecuritySchemeValue (
136+ client ,
137+ schemeDecorator ,
138+ schemeDecorator ,
139+ scheme
112140 ) ;
113- if ( securityAnn == null ) return ;
114- const securityDecorator : SecurityDecorator =
115- parseSecurityDecorator ( securityAnn ) ;
116- if ( securityDecorator == null || securityDecorator . Name === "" ) return ;
141+ }
117142
118- switch ( schemeDecorator . Type ) {
119- case "apiKey" :
120- switch ( schemeDecorator . SubType ) {
121- case "header" :
122- client . defaults . headers . common [ securityDecorator . Name ] =
123- scheme [ fname ] ;
124- break ;
125- case "query" :
126- client . defaults . params [ securityDecorator . Name ] = scheme [ fname ] ;
127- break ;
128- case "cookie" :
129- const securityDecoratorName : string = securityDecorator . Name ;
130- const val : string = scheme [ fname ] ;
131- client . defaults . headers . common [
132- "Cookie"
133- ] = `${ securityDecoratorName } =${ val } ` ;
134- break ;
135- default :
136- throw new Error ( "not supported" ) ;
137- }
138- break ;
139- case "openIdConnect" :
140- client . defaults . headers . common [ securityDecorator . Name ] = scheme [ fname ] ;
141- break ;
142- case "oauth2" :
143- client . defaults . headers . common [ securityDecorator . Name ] = scheme [ fname ] ;
144- break ;
145- case "http" :
146- switch ( schemeDecorator . SubType ) {
147- case "basic" :
148- break ;
149- case "bearer" :
150- client . defaults . headers . common [ securityDecorator . Name ] =
151- scheme [ fname ] ;
152- break ;
153- default :
154- throw new Error ( "not supported" ) ;
155- }
156- break ;
157- default :
158- throw new Error ( "not supported" ) ;
159- }
160- } ) ;
143+ return client ;
144+ }
145+
146+ function parseSecuritySchemeValue (
147+ client : AxiosInstance ,
148+ schemeDecorator : SecurityDecorator ,
149+ securityDecorator : SecurityDecorator ,
150+ value : any
151+ ) : AxiosInstance {
152+ switch ( schemeDecorator . Type ) {
153+ case "apiKey" :
154+ switch ( schemeDecorator . SubType ) {
155+ case "header" :
156+ client . defaults . headers . common [ securityDecorator . Name ] = value ;
157+ break ;
158+ case "query" :
159+ client . defaults . params [ securityDecorator . Name ] = value ;
160+ break ;
161+ case "cookie" :
162+ const securityDecoratorName : string = securityDecorator . Name ;
163+ const val : string = value ;
164+ client . defaults . headers . common [
165+ "Cookie"
166+ ] = `${ securityDecoratorName } =${ val } ` ;
167+ break ;
168+ default :
169+ throw new Error ( "not supported" ) ;
170+ }
171+ break ;
172+ case "openIdConnect" :
173+ client . defaults . headers . common [ securityDecorator . Name ] = value ;
174+ break ;
175+ case "oauth2" :
176+ client . defaults . headers . common [ securityDecorator . Name ] = value ;
177+ break ;
178+ case "http" :
179+ switch ( schemeDecorator . SubType ) {
180+ case "basic" :
181+ break ;
182+ case "bearer" :
183+ client . defaults . headers . common [ securityDecorator . Name ] = value ;
184+ break ;
185+ default :
186+ throw new Error ( "not supported" ) ;
187+ }
188+ break ;
189+ default :
190+ throw new Error ( "not supported" ) ;
191+ }
161192
162193 return client ;
163194}
0 commit comments