Skip to content

Commit f5aa790

Browse files
committed
feature: implement deepObject query params as per documentation.
Closes #19342.
1 parent b4378a6 commit f5aa790

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

modules/openapi-generator/src/main/resources/typescript-angular/api.base.service.mustache

+11-2
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,30 @@ export class BaseService {
2828
return consumes.indexOf('multipart/form-data') !== -1;
2929
}
3030

31-
protected addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams {
31+
protected addToHttpParams(httpParams: HttpParams, value: any, key?: string, isDeep?: boolean): HttpParams {
3232
// If the value is an object (but not a Date), recursively add its keys.
3333
if (typeof value === 'object' && !(value instanceof Date)) {
34+
if (isDeep) {
35+
return this.addToHttpParamsRecursive(httpParams, value, key, isDeep);
36+
}
3437
return this.addToHttpParamsRecursive(httpParams, value);
3538
}
3639
return this.addToHttpParamsRecursive(httpParams, value, key);
3740
}
3841

39-
protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams {
42+
protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep?: boolean): HttpParams {
4043
if (value === null || value === undefined) {
4144
return httpParams;
4245
}
4346
if (typeof value === 'object') {
4447
// If JSON format is preferred, key must be provided.
4548
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+
}
4655
return httpParams.append(key, JSON.stringify(value));
4756
}
4857
// Otherwise, if it's an array, add each element.

modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export class {{classname}} extends BaseService {
130130
{{/isArray}}
131131
{{^isArray}}
132132
localVarQueryParameters = this.addToHttpParams(localVarQueryParameters,
133-
<any>{{paramName}}, '{{baseName}}');
133+
<any>{{paramName}}, '{{baseName}}'{{#isDeepObject}}, true{{/isDeepObject}});
134134
{{/isArray}}
135135
{{/queryParams}}
136136

0 commit comments

Comments
 (0)