@@ -71,6 +71,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
71
71
72
72
const urlParams = parameters ?. filter ( ( p ) => p . in === "path" ) || [ ] ;
73
73
const queryParams = parameters ?. filter ( ( p ) => p . in === "query" ) || [ ] ;
74
+ const headerParams = parameters ?. filter ( ( p ) => p . in === "header" ) || [ ] ;
74
75
75
76
const isFormData = requestBody && "content" in requestBody && requestBody . content ?. [ "multipart/form-data" ] ;
76
77
@@ -112,13 +113,15 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
112
113
${ queryParams . map ( ( p ) => `["${ p . name } "]: data["${ p . name } "]` ) . join ( ",\n " ) }
113
114
};`
114
115
: "" ,
116
+
115
117
requestBodySchema ?. properties
116
118
? `const bodyData = {
117
119
${ Object . entries ( requestBodySchema . properties )
118
120
. map ( ( [ key ] ) => `["${ key } "]: data["${ key } "]` )
119
121
. join ( ",\n " ) }
120
122
};`
121
123
: "" ,
124
+
122
125
formDataSchema ?. properties
123
126
? `const bodyData = new FormData();
124
127
${ Object . entries ( formDataSchema . properties )
@@ -137,6 +140,12 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
137
140
isFormData
138
141
? "axiosConfig.headers = { ...axiosConfig.headers, 'Content-Type': 'multipart/form-data' };"
139
142
: "" ,
143
+ headerParams . length > 0
144
+ ? `const headerData = {
145
+ ${ headerParams . map ( ( p ) => `["${ p . name } "]: data["${ p . name } "]` ) . join ( ",\n " ) }
146
+ };`
147
+ : "" ,
148
+ headerParams . length > 0 ? "axiosConfig.headers = { ...axiosConfig.headers, ...headerData };" : "" ,
140
149
requestBody
141
150
? `const res = await apiClient.${ method } <${ responseType } >(url, ${ formDataSchema ?. properties || requestBodySchema ?. properties ? "bodyData" : "data" } , axiosConfig);`
142
151
: `const res = await apiClient.${ method } <${ responseType } >(url, axiosConfig);` ,
0 commit comments