11/* eslint-disable no-template-curly-in-string */
2- import { aliasIfReserved , aliasNameIfReserved } from './aliasIfReserved' ;
3- import { IdentifierFormat , makeIdentifier } from './makeIdentifier' ;
42import { objectTemplate } from './objectTemplate' ;
53
64export type ClientMethodTemplateArgs = {
@@ -110,29 +108,9 @@ export const clientMethodTemplate = (
110108 } )
111109 . join ( ' | ' ) ;
112110
113- const paramNames = headerParams
114- . concat ( queryParams )
115- . concat (
116- pathParams . map ( ( { name, type } ) => ( { name, required : true , type } ) )
117- )
118- . map ( ( { name } ) => name )
119- . concat ( bodyArg ? [ bodyArg . name ] : [ ] ) ;
120-
121- const decomposeParameters = paramNames . any ( )
122- ? `const {${ paramNames
123- . map ( name => makeIdentifier ( name , IdentifierFormat . camelCase ) )
124- . map ( aliasIfReserved )
125- . join ( ', ' ) } } = args;`
126- : '' ;
127-
128111 const composeQuery = queryParams . any ( )
129112 ? `const query = qs.stringify({ ${ queryParams
130- . map (
131- q =>
132- `["${ q . name } "]: ${ aliasNameIfReserved (
133- makeIdentifier ( q . name , IdentifierFormat . camelCase )
134- ) } `
135- )
113+ . map ( q => `["${ q . name } "]: args["${ q . name } "]` )
136114 . join ( ', ' ) } }${
137115 queryArrayFormat === 'comma' ? ", { arrayFormat: 'comma' }" : ''
138116 } );`
@@ -144,28 +122,24 @@ export const clientMethodTemplate = (
144122 ${ body . fields
145123 . map (
146124 f =>
147- `if (body. ${ f . name } ) formData.append('${ f . name } ', body. ${ f . name } );`
125+ `if (body[" ${ f . name } "] ) formData.append('${ f . name } ', body[" ${ f . name } "] );`
148126 )
149127 . join ( '\n' ) }
150128 `
151129 : '' ;
152130
153131 const url = `\`\${this.baseUrl}${ openApiPath . replace (
154132 / \{ (?: .* ?) \} / g,
155- x => `$${ x } `
133+ x => `$\{args[" ${ x . slice ( 1 , x . length - 1 ) } "] }`
156134 ) } ${ queryParams . any ( ) ? '?${query}' : '' } \``;
157135
158136 const headers = headerParams
159137 . map ( h => {
160- const localVarName = aliasNameIfReserved (
161- makeIdentifier ( h . name , IdentifierFormat . camelCase )
162- ) ;
163-
164138 if ( h . required ) {
165- return `["${ h . name } "]: ${ localVarName } ` ;
139+ return `["${ h . name } "]: args[" ${ h . name } "] ` ;
166140 }
167141
168- return `...(typeof ${ localVarName } !== 'undefined' && ${ localVarName } !== null ? { ["${ h . name } "]: ${ localVarName } } : {})` ;
142+ return `...(typeof args[" ${ h . name } "] !== 'undefined' && args[" ${ h . name } "] !== null ? { ["${ h . name } "]: args[" ${ h . name } "] } : {})` ;
169143 } )
170144 . concat (
171145 body ?. type === 'json' ? [ "'Content-Type': 'application/json'" ] : [ ]
@@ -175,7 +149,7 @@ export const clientMethodTemplate = (
175149 ${ [
176150 'method' ,
177151
178- ...( body ?. type === 'json' ? [ 'body: JSON.stringify(body)' ] : [ ] ) ,
152+ ...( body ?. type === 'json' ? [ 'body: JSON.stringify(args. body)' ] : [ ] ) ,
179153
180154 ...( body ?. type === 'form' ? [ 'body: formData' ] : [ ] ) ,
181155
@@ -228,8 +202,6 @@ export const clientMethodTemplate = (
228202 return `public async "${ methodName } "(${ functionArgumentSignature } ):
229203 Promise<${ responseType } > {
230204
231- ${ decomposeParameters }
232-
233205 ${ composeQuery }
234206
235207 ${ composeFormData }
0 commit comments