Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class BaseService {
}

return Object.keys(value as Record<string, any>).reduce(
(hp, k) => hp.append(`${key}[${k}]`, value[k]),
(hp, k) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k]),
httpParams,
);
} else if (paramStyle === QueryParamStyle.Json) {
Expand Down Expand Up @@ -69,8 +69,8 @@ export class BaseService {
// Otherwise, if it's an object, add each field.
if (paramStyle === QueryParamStyle.Form) {
if (explode) {
Object.keys(value).forEach(k => {
httpParams = this.addToHttpParams(httpParams, k, value[k], paramStyle, explode);
Object.entries(value).forEach(([k, v]) => {
httpParams = this.addToHttpParams(httpParams, `${key}.${k}`, v, paramStyle, explode);
});
return httpParams;
} else {
Expand All @@ -85,4 +85,25 @@ export class BaseService {
}
}
}

private addToHttpParamsDeepObject(httpParams: OpenApiHttpParams, key: string, value: any | null | undefined): OpenApiHttpParams {
if (value == null) {
return httpParams;
} else if (value instanceof Date) {
return httpParams.append(key, value.toISOString());
} else if (Object(value) !== value) {
return httpParams.append(key, value.toString());
} else if (Array.isArray(value) || value instanceof Set) {
const array = Array.isArray(value) ? value : Array.from(value);
array.forEach((item, index) => {
httpParams = this.addToHttpParamsDeepObject(httpParams, `${key}[${index}]`, item);
});
return httpParams;
} else {
return Object.entries(value).reduce(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Object.entries is not available under the generator’s current TypeScript lib setup, so this change breaks generated Angular builds/type-checking.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/typescript-angular/api.base.service.mustache, line 103:

<comment>`Object.entries` is not available under the generator’s current TypeScript lib setup, so this change breaks generated Angular builds/type-checking.</comment>

<file context>
@@ -85,4 +85,25 @@ export class BaseService {
+            });
+            return httpParams;
+        } else {
+            return Object.entries(value).reduce(
+                (hp, [k, v]) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, v),
+                httpParams,
</file context>
Suggested change
return Object.entries(value).reduce(
return Object.keys(value).reduce(
(hp, k) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k]),
httpParams,
);

(hp, [k, v]) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, v),
httpParams,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ public void testDeepObject() throws IOException {
final String fileContents = Files.readString(Paths.get(output + "/api/default.service.ts"));
assertThat(fileContents).containsSubsequence("'options',\n", "<any>options,\n", "QueryParamStyle.DeepObject,\n", "true,\n");
assertThat(fileContents).containsSubsequence("'inputOptions',\n", "<any>inputOptions,\n", "QueryParamStyle.DeepObject,\n", "true,\n");

final String baseServiceContents = Files.readString(Paths.get(output + "/api.base.service.ts"));
assertThat(baseServiceContents).contains("this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k])");
assertThat(baseServiceContents).contains("this.addToHttpParamsDeepObject(httpParams, `${key}[${index}]`, item)");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class BaseService {
}

return Object.keys(value as Record<string, any>).reduce(
(hp, k) => hp.append(`${key}[${k}]`, value[k]),
(hp, k) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k]),
httpParams,
);
} else if (paramStyle === QueryParamStyle.Json) {
Expand All @@ -76,8 +76,8 @@ export class BaseService {
// Otherwise, if it's an object, add each field.
if (paramStyle === QueryParamStyle.Form) {
if (explode) {
Object.keys(value).forEach(k => {
httpParams = this.addToHttpParams(httpParams, k, value[k], paramStyle, explode);
Object.entries(value).forEach(([k, v]) => {
httpParams = this.addToHttpParams(httpParams, `${key}.${k}`, v, paramStyle, explode);
});
return httpParams;
} else {
Expand All @@ -92,4 +92,25 @@ export class BaseService {
}
}
}

private addToHttpParamsDeepObject(httpParams: OpenApiHttpParams, key: string, value: any | null | undefined): OpenApiHttpParams {
if (value == null) {
return httpParams;
} else if (value instanceof Date) {
return httpParams.append(key, value.toISOString());
} else if (Object(value) !== value) {
return httpParams.append(key, value.toString());
} else if (Array.isArray(value) || value instanceof Set) {
const array = Array.isArray(value) ? value : Array.from(value);
array.forEach((item, index) => {
httpParams = this.addToHttpParamsDeepObject(httpParams, `${key}[${index}]`, item);
});
return httpParams;
} else {
return Object.entries(value).reduce(
(hp, [k, v]) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, v),
httpParams,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class BaseService {
}

return Object.keys(value as Record<string, any>).reduce(
(hp, k) => hp.append(`${key}[${k}]`, value[k]),
(hp, k) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k]),
httpParams,
);
} else if (paramStyle === QueryParamStyle.Json) {
Expand All @@ -76,8 +76,8 @@ export class BaseService {
// Otherwise, if it's an object, add each field.
if (paramStyle === QueryParamStyle.Form) {
if (explode) {
Object.keys(value).forEach(k => {
httpParams = this.addToHttpParams(httpParams, k, value[k], paramStyle, explode);
Object.entries(value).forEach(([k, v]) => {
httpParams = this.addToHttpParams(httpParams, `${key}.${k}`, v, paramStyle, explode);
});
return httpParams;
} else {
Expand All @@ -92,4 +92,25 @@ export class BaseService {
}
}
}

private addToHttpParamsDeepObject(httpParams: OpenApiHttpParams, key: string, value: any | null | undefined): OpenApiHttpParams {
if (value == null) {
return httpParams;
} else if (value instanceof Date) {
return httpParams.append(key, value.toISOString());
} else if (Object(value) !== value) {
return httpParams.append(key, value.toString());
} else if (Array.isArray(value) || value instanceof Set) {
const array = Array.isArray(value) ? value : Array.from(value);
array.forEach((item, index) => {
httpParams = this.addToHttpParamsDeepObject(httpParams, `${key}[${index}]`, item);
});
return httpParams;
} else {
return Object.entries(value).reduce(
(hp, [k, v]) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, v),
httpParams,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class BaseService {
}

return Object.keys(value as Record<string, any>).reduce(
(hp, k) => hp.append(`${key}[${k}]`, value[k]),
(hp, k) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k]),
httpParams,
);
} else if (paramStyle === QueryParamStyle.Json) {
Expand All @@ -76,8 +76,8 @@ export class BaseService {
// Otherwise, if it's an object, add each field.
if (paramStyle === QueryParamStyle.Form) {
if (explode) {
Object.keys(value).forEach(k => {
httpParams = this.addToHttpParams(httpParams, k, value[k], paramStyle, explode);
Object.entries(value).forEach(([k, v]) => {
httpParams = this.addToHttpParams(httpParams, `${key}.${k}`, v, paramStyle, explode);
});
return httpParams;
} else {
Expand All @@ -92,4 +92,25 @@ export class BaseService {
}
}
}

private addToHttpParamsDeepObject(httpParams: OpenApiHttpParams, key: string, value: any | null | undefined): OpenApiHttpParams {
if (value == null) {
return httpParams;
} else if (value instanceof Date) {
return httpParams.append(key, value.toISOString());
} else if (Object(value) !== value) {
return httpParams.append(key, value.toString());
} else if (Array.isArray(value) || value instanceof Set) {
const array = Array.isArray(value) ? value : Array.from(value);
array.forEach((item, index) => {
httpParams = this.addToHttpParamsDeepObject(httpParams, `${key}[${index}]`, item);
});
return httpParams;
} else {
return Object.entries(value).reduce(
(hp, [k, v]) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, v),
httpParams,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class BaseService {
}

return Object.keys(value as Record<string, any>).reduce(
(hp, k) => hp.append(`${key}[${k}]`, value[k]),
(hp, k) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k]),
httpParams,
);
} else if (paramStyle === QueryParamStyle.Json) {
Expand All @@ -76,8 +76,8 @@ export class BaseService {
// Otherwise, if it's an object, add each field.
if (paramStyle === QueryParamStyle.Form) {
if (explode) {
Object.keys(value).forEach(k => {
httpParams = this.addToHttpParams(httpParams, k, value[k], paramStyle, explode);
Object.entries(value).forEach(([k, v]) => {
httpParams = this.addToHttpParams(httpParams, `${key}.${k}`, v, paramStyle, explode);
});
return httpParams;
} else {
Expand All @@ -92,4 +92,25 @@ export class BaseService {
}
}
}

private addToHttpParamsDeepObject(httpParams: OpenApiHttpParams, key: string, value: any | null | undefined): OpenApiHttpParams {
if (value == null) {
return httpParams;
} else if (value instanceof Date) {
return httpParams.append(key, value.toISOString());
} else if (Object(value) !== value) {
return httpParams.append(key, value.toString());
} else if (Array.isArray(value) || value instanceof Set) {
const array = Array.isArray(value) ? value : Array.from(value);
array.forEach((item, index) => {
httpParams = this.addToHttpParamsDeepObject(httpParams, `${key}[${index}]`, item);
});
return httpParams;
} else {
return Object.entries(value).reduce(
(hp, [k, v]) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, v),
httpParams,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class BaseService {
}

return Object.keys(value as Record<string, any>).reduce(
(hp, k) => hp.append(`${key}[${k}]`, value[k]),
(hp, k) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k]),
httpParams,
);
} else if (paramStyle === QueryParamStyle.Json) {
Expand Down Expand Up @@ -77,8 +77,8 @@ export class BaseService {
// Otherwise, if it's an object, add each field.
if (paramStyle === QueryParamStyle.Form) {
if (explode) {
Object.keys(value).forEach(k => {
httpParams = this.addToHttpParams(httpParams, k, value[k], paramStyle, explode);
Object.entries(value).forEach(([k, v]) => {
httpParams = this.addToHttpParams(httpParams, `${key}.${k}`, v, paramStyle, explode);
});
return httpParams;
} else {
Expand All @@ -93,4 +93,25 @@ export class BaseService {
}
}
}

private addToHttpParamsDeepObject(httpParams: OpenApiHttpParams, key: string, value: any | null | undefined): OpenApiHttpParams {
if (value == null) {
return httpParams;
} else if (value instanceof Date) {
return httpParams.append(key, value.toISOString());
} else if (Object(value) !== value) {
return httpParams.append(key, value.toString());
} else if (Array.isArray(value) || value instanceof Set) {
const array = Array.isArray(value) ? value : Array.from(value);
array.forEach((item, index) => {
httpParams = this.addToHttpParamsDeepObject(httpParams, `${key}[${index}]`, item);
});
return httpParams;
} else {
return Object.entries(value).reduce(
(hp, [k, v]) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, v),
httpParams,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class BaseService {
}

return Object.keys(value as Record<string, any>).reduce(
(hp, k) => hp.append(`${key}[${k}]`, value[k]),
(hp, k) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k]),
httpParams,
);
} else if (paramStyle === QueryParamStyle.Json) {
Expand Down Expand Up @@ -77,8 +77,8 @@ export class BaseService {
// Otherwise, if it's an object, add each field.
if (paramStyle === QueryParamStyle.Form) {
if (explode) {
Object.keys(value).forEach(k => {
httpParams = this.addToHttpParams(httpParams, k, value[k], paramStyle, explode);
Object.entries(value).forEach(([k, v]) => {
httpParams = this.addToHttpParams(httpParams, `${key}.${k}`, v, paramStyle, explode);
});
return httpParams;
} else {
Expand All @@ -93,4 +93,25 @@ export class BaseService {
}
}
}

private addToHttpParamsDeepObject(httpParams: OpenApiHttpParams, key: string, value: any | null | undefined): OpenApiHttpParams {
if (value == null) {
return httpParams;
} else if (value instanceof Date) {
return httpParams.append(key, value.toISOString());
} else if (Object(value) !== value) {
return httpParams.append(key, value.toString());
} else if (Array.isArray(value) || value instanceof Set) {
const array = Array.isArray(value) ? value : Array.from(value);
array.forEach((item, index) => {
httpParams = this.addToHttpParamsDeepObject(httpParams, `${key}[${index}]`, item);
});
return httpParams;
} else {
return Object.entries(value).reduce(
(hp, [k, v]) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, v),
httpParams,
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class BaseService {
}

return Object.keys(value as Record<string, any>).reduce(
(hp, k) => hp.append(`${key}[${k}]`, value[k]),
(hp, k) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, value[k]),
httpParams,
);
} else if (paramStyle === QueryParamStyle.Json) {
Expand Down Expand Up @@ -77,8 +77,8 @@ export class BaseService {
// Otherwise, if it's an object, add each field.
if (paramStyle === QueryParamStyle.Form) {
if (explode) {
Object.keys(value).forEach(k => {
httpParams = this.addToHttpParams(httpParams, k, value[k], paramStyle, explode);
Object.entries(value).forEach(([k, v]) => {
httpParams = this.addToHttpParams(httpParams, `${key}.${k}`, v, paramStyle, explode);
});
return httpParams;
} else {
Expand All @@ -93,4 +93,25 @@ export class BaseService {
}
}
}

private addToHttpParamsDeepObject(httpParams: OpenApiHttpParams, key: string, value: any | null | undefined): OpenApiHttpParams {
if (value == null) {
return httpParams;
} else if (value instanceof Date) {
return httpParams.append(key, value.toISOString());
} else if (Object(value) !== value) {
return httpParams.append(key, value.toString());
} else if (Array.isArray(value) || value instanceof Set) {
const array = Array.isArray(value) ? value : Array.from(value);
array.forEach((item, index) => {
httpParams = this.addToHttpParamsDeepObject(httpParams, `${key}[${index}]`, item);
});
return httpParams;
} else {
return Object.entries(value).reduce(
(hp, [k, v]) => this.addToHttpParamsDeepObject(hp, `${key}[${k}]`, v),
httpParams,
);
}
}
}
Loading
Loading