Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][typescript-angular] 7.12.0 refactoring changes behaviour of http params #20998

Open
MrAlexand0r opened this issue Mar 31, 2025 · 3 comments

Comments

@MrAlexand0r
Copy link

MrAlexand0r commented Mar 31, 2025

Description

JS Objects used to be flattened into individual parameters. Now they just get JSON.stringified.

Example:
Page Object:

{
   page: 1,
   items: 10
}

7.11.0

/api/request?page=1&items=10

7.12.0

/api/request?page={page:1,items:10}

There is no config to set the behaviour to how it was previously.

openapi-generator version

7.11.0

    private addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams {
        if (value == null) {
            return httpParams;
        }

        if (typeof value === "object") {
            if (Array.isArray(value)) {
                (value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key));
            } else if (value instanceof Date) {
                if (key != null) {
                    httpParams = httpParams.append(key, (value as Date).toISOString().substring(0, 10));
                } else {
                   throw Error("key may not be null if value is Date");
                }
            } else {
                Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive(
                    httpParams, value[k], key != null ? `${key}.${k}` : k));
            }
        } else if (key != null) {
            httpParams = httpParams.append(key, value);
        } else {
            throw Error("key may not be null if value is not object or array");
        }
        return httpParams;
    }

7.12.0

   protected addToHttpParamsRecursive(httpParams: HttpParams, value?: any, key?: string): HttpParams {
        if (value === null || value === undefined) {
            return httpParams;
        }
        if (typeof value === 'object') {
            // If JSON format is preferred, key must be provided.
            if (key != null) {
                return httpParams.append(key, JSON.stringify(value));
            }
            // Otherwise, if it's an array, add each element.
            if (Array.isArray(value)) {
                value.forEach(elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key));
            } else if (value instanceof Date) {
                if (key != null) {
                    httpParams = httpParams.append(key, value.toISOString());
                } else {
                    throw Error("key may not be null if value is Date");
                }
            } else {
                Object.keys(value).forEach(k => {
                    const paramKey = key ? `${key}.${k}` : k;
                    httpParams = this.addToHttpParamsRecursive(httpParams, value[k], paramKey);
                });
            }
            return httpParams;
        } else if (key != null) {
            return httpParams.append(key, value);
        }
        throw Error("key may not be null if value is not object or array");
    }
Steps to reproduce

Run openapi-generator with the latest version

Related issues/PRs

This merge causes the issue:
#20681

Suggest a fix

I would suggest to either add a config to enable/disable json http params, or revert the addToHttpParamsRecursive method to how it was previously

@MrAlexand0r MrAlexand0r changed the title [BUG][typescript-angualr] 7.12.0 refactoring changes behaviour of http params [BUG][typescript-angular] 7.12.0 refactoring changes behaviour of http params Mar 31, 2025
@bhahn57570
Copy link

Issue already open #20980 please close both if the problem is fixed.

@MrAlexand0r
Copy link
Author

After looking at related issues (#20799, #20850)

I can see that a fix has been implemented, but for my case, serializing the object when a key is provided does not solve the issue.

In the case of having a spring boot appliciation with spring docs generated api spec, using the @pageable annotation for automatic query params resolution cases the query param to get the key "pageable" and in turn telling it to be parsed into json.

Therefore a config would be nice to tell the generator to not JSON.stringify

@bhahn57570
Copy link

I am exactly in the same case so yes could be great to have the option to switch between the 2 implementations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants