22 * Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
33 */
44
5- import { AxiosInstance } from "axios" ;
6-
75const securityMetadataKey = "security" ;
86
9- export function createSecurityClient (
10- client : AxiosInstance ,
7+ export type SecurityProperties = {
8+ params : Record < string , string > ,
9+ headers : Record < string , string > ,
10+ }
11+
12+ export function parseSecurityProperties (
1113 security : any
12- ) : AxiosInstance {
13- return parseSecurityClass ( client , security ) ;
14+ ) : SecurityProperties {
15+ return parseSecurityClass ( security ) ;
1416}
1517
1618function parseSecurityDecorator ( securityAnn : string ) : SecurityDecorator {
@@ -51,10 +53,13 @@ function parseSecurityDecorator(securityAnn: string): SecurityDecorator {
5153}
5254
5355function parseSecurityClass (
54- client : AxiosInstance ,
5556 security : any
56- ) : AxiosInstance {
57+ ) : SecurityProperties {
5758 const fieldNames : string [ ] = Object . getOwnPropertyNames ( security ) ;
59+ const properties : SecurityProperties = {
60+ params : { } ,
61+ headers : { } ,
62+ }
5863 fieldNames . forEach ( ( fname ) => {
5964 const securityAnn : string = Reflect . getMetadata (
6065 securityMetadataKey ,
@@ -69,23 +74,23 @@ function parseSecurityClass(
6974 const value = security [ fname ] ;
7075
7176 if ( securityDecorator . Option ) {
72- return parseSecurityOption ( client , value ) ;
77+ return parseSecurityOption ( properties , value ) ;
7378 } else if ( securityDecorator . Scheme ) {
7479 if ( securityDecorator . SubType === "basic" && value !== Object ( value ) ) {
75- return parseSecurityScheme ( client , securityDecorator , security ) ;
80+ return parseSecurityScheme ( properties , securityDecorator , security ) ;
7681 } else {
77- client = parseSecurityScheme ( client , securityDecorator , value ) ;
82+ return parseSecurityScheme ( properties , securityDecorator , value ) ;
7883 }
7984 }
8085 } ) ;
8186
82- return client ;
87+ return properties ;
8388}
8489
8590function parseSecurityOption (
86- client : AxiosInstance ,
91+ properties : SecurityProperties ,
8792 optionType : any
88- ) : AxiosInstance {
93+ ) : void {
8994 const fieldNames : string [ ] = Object . getOwnPropertyNames ( optionType ) ;
9095 fieldNames . forEach ( ( fname ) => {
9196 const securityAnn : string = Reflect . getMetadata (
@@ -97,23 +102,21 @@ function parseSecurityOption(
97102 const securityDecorator : SecurityDecorator =
98103 parseSecurityDecorator ( securityAnn ) ;
99104 if ( securityDecorator == null || ! securityDecorator . Scheme ) return ;
100- return parseSecurityScheme ( client , securityDecorator , optionType [ fname ] ) ;
105+ return parseSecurityScheme ( properties , securityDecorator , optionType [ fname ] ) ;
101106 } ) ;
102-
103- return client ;
104107}
105108
106109function parseSecurityScheme (
107- client : AxiosInstance ,
110+ properties : SecurityProperties ,
108111 schemeDecorator : SecurityDecorator ,
109112 scheme : any
110- ) : AxiosInstance {
113+ ) : void {
111114 if ( scheme === Object ( scheme ) ) {
112115 if (
113116 schemeDecorator . Type === "http" &&
114117 schemeDecorator . SubType === "basic"
115118 ) {
116- return parseBasicAuthScheme ( client , scheme ) ;
119+ return parseBasicAuthScheme ( properties , scheme ) ;
117120 }
118121
119122 const fieldNames : string [ ] = Object . getOwnPropertyNames ( scheme ) ;
@@ -128,64 +131,62 @@ function parseSecurityScheme(
128131 parseSecurityDecorator ( securityAnn ) ;
129132 if ( securityDecorator == null || securityDecorator . Name === "" ) return ;
130133
131- client = parseSecuritySchemeValue (
132- client ,
134+ return parseSecuritySchemeValue (
135+ properties ,
133136 schemeDecorator ,
134137 securityDecorator ,
135138 scheme [ fname ]
136139 ) ;
137140 } ) ;
138141 } else {
139- client = parseSecuritySchemeValue (
140- client ,
142+ return parseSecuritySchemeValue (
143+ properties ,
141144 schemeDecorator ,
142145 schemeDecorator ,
143146 scheme
144147 ) ;
145148 }
146-
147- return client ;
148149}
149150
150151function parseSecuritySchemeValue (
151- client : AxiosInstance ,
152+ properties : SecurityProperties ,
152153 schemeDecorator : SecurityDecorator ,
153154 securityDecorator : SecurityDecorator ,
154155 value : any
155- ) : AxiosInstance {
156+ ) : void {
156157 switch ( schemeDecorator . Type ) {
157158 case "apiKey" :
158159 switch ( schemeDecorator . SubType ) {
159160 case "header" :
160- client . defaults . headers . common [ securityDecorator . Name ] = value ;
161+ properties . headers [ securityDecorator . Name ] = value ;
161162 break ;
162163 case "query" :
163- client . defaults . params [ securityDecorator . Name ] = value ;
164+ properties . params [ securityDecorator . Name ] = value ;
164165 break ;
165166 case "cookie" : {
166167 const securityDecoratorName : string = securityDecorator . Name ;
167168 const val : string = value ;
168- client . defaults . headers . common [
169+ properties . headers [
169170 "Cookie"
170- ] = `${ securityDecoratorName } =${ val } ` ;
171+ ] = `${ securityDecoratorName } =${ val } ` ;
171172 break ;
172173 }
173174 default :
174175 throw new Error ( "not supported" ) ;
175176 }
176177 break ;
177178 case "openIdConnect" :
178- client . defaults . headers . common [ securityDecorator . Name ] = value ;
179+ properties . headers [ securityDecorator . Name ] = value ;
179180 break ;
180181 case "oauth2" :
181- client . defaults . headers . common [ securityDecorator . Name ] = value ;
182+ properties . headers [ securityDecorator . Name ] = value ;
182183 break ;
183184 case "http" :
184185 switch ( schemeDecorator . SubType ) {
185186 case "basic" :
186187 break ;
187188 case "bearer" :
188- client . defaults . headers . common [ securityDecorator . Name ] = value . toLowerCase ( ) . startsWith ( "bearer " ) ? value : `Bearer ${ value } ` ;
189+ properties . headers [ securityDecorator . Name ] = value . toLowerCase ( ) . startsWith ( "bearer " ) ? value : `Bearer ${ value } ` ;
189190 break ;
190191 default :
191192 throw new Error ( "not supported" ) ;
@@ -194,14 +195,12 @@ function parseSecuritySchemeValue(
194195 default :
195196 throw new Error ( "not supported" ) ;
196197 }
197-
198- return client ;
199198}
200199
201200function parseBasicAuthScheme (
202- client : AxiosInstance ,
201+ properties : SecurityProperties ,
203202 scheme : any
204- ) : AxiosInstance {
203+ ) : void {
205204 let username ,
206205 password = "" ;
207206
@@ -227,11 +226,7 @@ function parseBasicAuthScheme(
227226 }
228227 } ) ;
229228
230- client . defaults . headers . common [ "Authorization" ] = `Basic ${ Buffer . from (
231- `${ username } :${ password } `
232- ) . toString ( "base64" ) } `;
233-
234- return client ;
229+ properties . headers [ "Authorization" ] = `Basic ${ Buffer . from ( `${ username } :${ password } ` ) . toString ( 'base64' ) } ` ;
235230}
236231
237232class SecurityDecorator {
0 commit comments