Skip to content

Commit e5a8052

Browse files
committed
fix: add support for header params in spec
1 parent 0285d1c commit e5a8052

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/generator/clientGenerator.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
7171

7272
const urlParams = parameters?.filter((p) => p.in === "path") || [];
7373
const queryParams = parameters?.filter((p) => p.in === "query") || [];
74+
const headerParams = parameters?.filter((p) => p.in === "header") || [];
7475

7576
const isFormData = requestBody && "content" in requestBody && requestBody.content?.["multipart/form-data"];
7677

@@ -112,13 +113,15 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
112113
${queryParams.map((p) => `["${p.name}"]: data["${p.name}"]`).join(",\n ")}
113114
};`
114115
: "",
116+
115117
requestBodySchema?.properties
116118
? `const bodyData = {
117119
${Object.entries(requestBodySchema.properties)
118120
.map(([key]) => `["${key}"]: data["${key}"]`)
119121
.join(",\n ")}
120122
};`
121123
: "",
124+
122125
formDataSchema?.properties
123126
? `const bodyData = new FormData();
124127
${Object.entries(formDataSchema.properties)
@@ -137,6 +140,12 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
137140
isFormData
138141
? "axiosConfig.headers = { ...axiosConfig.headers, 'Content-Type': 'multipart/form-data' };"
139142
: "",
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 };" : "",
140149
requestBody
141150
? `const res = await apiClient.${method}<${responseType}>(url, ${formDataSchema?.properties || requestBodySchema?.properties ? "bodyData" : "data"}, axiosConfig);`
142151
: `const res = await apiClient.${method}<${responseType}>(url, axiosConfig);`,

0 commit comments

Comments
 (0)