Skip to content

Commit 4e321df

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

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,27 @@ 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)) {
3434
return this.addToHttpParamsRecursive(httpParams, value);
3535
}
36-
return this.addToHttpParamsRecursive(httpParams, value, key);
36+
return this.addToHttpParamsRecursive(httpParams, value, key, isDeep);
3737
}
3838

39-
protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams {
39+
protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string, isDeep?: boolean): HttpParams {
4040
if (value === null || value === undefined) {
4141
return httpParams;
4242
}
4343
if (typeof value === 'object') {
4444
// If JSON format is preferred, key must be provided.
4545
if (key != null) {
46+
if (isDeep) {
47+
return Object.entries(value as Record<string, any>).reduce(
48+
(hp, [k, v]) => hp.append(`${key}[${k}]`, v),
49+
httpParams,
50+
);
51+
}
4652
return httpParams.append(key, JSON.stringify(value));
4753
}
4854
// 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)