@kubb/plugin-axios 5.9.0 → 5.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +35 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +35 -17
- package/dist/index.js.map +1 -1
- package/dist/templates/axios.d.ts +27 -55
- package/docs/options.md +1 -1
- package/package.json +5 -5
- package/templates/axios.ts +170 -266
- package/templates/serializers.ts +13 -5
package/templates/serializers.ts
CHANGED
|
@@ -150,12 +150,17 @@ function jsonReplacer(_key: string, value: unknown): unknown {
|
|
|
150
150
|
|
|
151
151
|
function appendFormDataValue({ formData, key, value, contentType }: { formData: FormData; key: string; value: unknown; contentType?: string }): void {
|
|
152
152
|
if (value === undefined || value === null) return
|
|
153
|
-
if (value instanceof Blob)
|
|
154
|
-
|
|
153
|
+
if (value instanceof Blob) {
|
|
154
|
+
formData.append(key, value)
|
|
155
|
+
return
|
|
156
|
+
}
|
|
157
|
+
if (typeof value === 'object' && !(value instanceof Date)) {
|
|
155
158
|
const json = JSON.stringify(value, jsonReplacer)
|
|
156
159
|
// A part's media type can only be set by wrapping the value in a typed Blob.
|
|
157
160
|
formData.append(key, contentType ? new Blob([json], { type: contentType }) : json)
|
|
158
|
-
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
formData.append(key, toValue(value))
|
|
159
164
|
}
|
|
160
165
|
|
|
161
166
|
/**
|
|
@@ -179,8 +184,11 @@ export const defaultBodySerializer: BodySerializer = ({ body, contentType, encod
|
|
|
179
184
|
const formData = new FormData()
|
|
180
185
|
for (const [key, value] of Object.entries(body as Record<string, unknown>)) {
|
|
181
186
|
const partContentType = encoding?.[key]?.contentType
|
|
182
|
-
if (Array.isArray(value))
|
|
183
|
-
|
|
187
|
+
if (Array.isArray(value)) {
|
|
188
|
+
for (const item of value) appendFormDataValue({ formData, key, value: item, contentType: partContentType })
|
|
189
|
+
continue
|
|
190
|
+
}
|
|
191
|
+
appendFormDataValue({ formData, key, value, contentType: partContentType })
|
|
184
192
|
}
|
|
185
193
|
return formData
|
|
186
194
|
}
|