@@ -101,7 +101,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
101
101
const urlWithParams = urlParams . length > 0 ? `\`${ path . replace ( / { ( \w + ) } / g, "${data.$1}" ) } \`` : `"${ path } "` ;
102
102
103
103
const methodBody = [
104
- `${ hasData ? "const { axiosConfig, ...data } = props || {};" : "const { axiosConfig } = props || {};" } ` ,
104
+ `${ hasData ? "const { axiosConfig = {} , ...data } = props || {};" : "const { axiosConfig } = props || {};" } ` ,
105
105
"const apiClient = getApiClient();" ,
106
106
`const url = ${ urlWithParams } ;` ,
107
107
queryParams . length > 0
@@ -117,29 +117,35 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
117
117
};`
118
118
: "" ,
119
119
formDataSchema ?. properties
120
- ? `const formData = new FormData();
120
+ ? `const bodyData = new FormData();
121
121
${ Object . entries ( formDataSchema . properties )
122
122
. map ( ( [ key , prop ] ) => {
123
123
const schemaProperty = prop as OpenAPIV3 . SchemaObject ;
124
124
const isBinary = schemaProperty . format === "binary" ;
125
125
return formDataSchema ?. required ?. includes ( key )
126
- ? `formData .append("${ key } ", ${ isBinary ? "" : "String(" } ${ queryParams . length > 0 ? "bodyData" : "data" } .${ key } ${ isBinary ? "" : ")" } );`
126
+ ? `bodyData .append("${ key } ", ${ isBinary ? "" : "String(" } ${ queryParams . length > 0 ? "bodyData" : "data" } .${ key } ${ isBinary ? "" : ")" } );`
127
127
: `if (${ queryParams . length > 0 ? "bodyData" : "data" } .${ key } != null) {
128
- formData .append("${ key } ", ${ isBinary ? "" : "String(" } ${ queryParams . length > 0 ? "bodyData" : "data" } .${ key } ${ isBinary ? "" : ")" } );
128
+ bodyData .append("${ key } ", ${ isBinary ? "" : "String(" } ${ queryParams . length > 0 ? "bodyData" : "data" } .${ key } ${ isBinary ? "" : ")" } );
129
129
}` ;
130
130
} )
131
131
. join ( "\n " ) } `
132
132
: "" ,
133
- `const res = await apiClient.${ method } <${ responseType } >(url, {
134
- ${ queryParams . length > 0 ? "params: queryData," : "" }
135
- ${ requestBody ? `data: ${ isFormData ? "formData" : "bodyData" } ,` : "" }
136
- ${ isFormData ? `config: { headers: { 'Content-Type': 'multipart/form-data', ...axiosConfig?.headers }, ...axiosConfig },` : "...axiosConfig" }
137
- });
138
- return res.data;` ,
133
+ queryParams . length > 0 ? "axiosConfig.params = queryData;" : "" ,
134
+ isFormData
135
+ ? "axiosConfig.headers = { ...axiosConfig.headers, 'Content-Type': 'multipart/form-data' };"
136
+ : "" ,
137
+ requestBody
138
+ ? `const res = await apiClient.${ method } <${ responseType } >(url, bodyData, axiosConfig);`
139
+ : `const res = await apiClient.${ method } <${ responseType } >(url, axiosConfig);` ,
140
+ "return res.data;" ,
139
141
]
140
142
. filter ( Boolean )
141
143
. join ( "\n " ) ;
142
144
145
+ // ${queryParams.length > 0 ? "params: queryData," : ""}
146
+ // ${requestBody ? `data: ${isFormData ? "formData" : "bodyData"},` : "" }
147
+ // ${isFormData ? `config: { headers: { 'Content-Type': 'multipart/form-data', ...axiosConfig?.headers }, ...axiosConfig },` : "...axiosConfig" }
148
+
143
149
const requestParms = hasData
144
150
? `props: T.${ pascalCase ( operationId ) } Params & { axiosConfig?: AxiosRequestConfig; }`
145
151
: "props?: { axiosConfig?: AxiosRequestConfig }" ;
0 commit comments