@@ -28,21 +28,30 @@ export class BaseService {
28
28
return consumes.indexOf(' multipart/form-data' ) !== -1;
29
29
}
30
30
31
- protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams {
31
+ protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep?: boolean ): HttpParams {
32
32
// If the value is an object (but not a Date), recursively add its keys.
33
33
if (typeof value === ' object' && ! (value instanceof Date)) {
34
+ if (isDeep) {
35
+ return this.addToHttpParamsRecursive(httpParams, value, key, isDeep);
36
+ }
34
37
return this.addToHttpParamsRecursive(httpParams, value);
35
38
}
36
39
return this.addToHttpParamsRecursive(httpParams, value, key);
37
40
}
38
41
39
- protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams {
42
+ protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep?: boolean ): HttpParams {
40
43
if (value === null || value === undefined) {
41
44
return httpParams;
42
45
}
43
46
if (typeof value === 'object') {
44
47
// If JSON format is preferred, key must be provided.
45
48
if (key != null) {
49
+ if (isDeep) {
50
+ return Object.entries(value as Record< string, any> ).reduce(
51
+ (hp, [k, v]) => hp.append(`${key} [${ k} ]`, v),
52
+ httpParams,
53
+ );
54
+ }
46
55
return httpParams.append(key, JSON.stringify(value));
47
56
}
48
57
// Otherwise, if it's an array, add each element.
0 commit comments