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

RequestSpecification.queryParam does not respect null values #1751

Open
maxfd3v opened this issue Nov 23, 2023 · 3 comments
Open

RequestSpecification.queryParam does not respect null values #1751

maxfd3v opened this issue Nov 23, 2023 · 3 comments

Comments

@maxfd3v
Copy link

maxfd3v commented Nov 23, 2023

RequestSpecification.queryParam ("myParam", null)

Will be passed to the target API as a "" (Blank String)

One has to test the incoming parameter and skip adding a queryParam to make it work

@DeMol-EE
Copy link

Not sure what @maxfd3v expects to happen, but I for one would like it if the query param was simply skipped when the passed value is null. I realise that it’s possible to wrap adding the query param in an if with a null check, but it looks verbose, especially when used in a parametrized junit 5 test:

compare

        RequestSpecification req = RestAssured.given();
        if (foo != null) {
            req.queryParam("foo", foo);
        }
        if (bar != null) {
            req.queryParam("bar", bar);
        }
        Response res = req.get();

to

        RequestSpecification req = RestAssured.given()
            .queryParam("foo", foo)
            .queryParam("bar", bar);
        Response res = req.get();

I feel like it would be easy to draft a PR for this, but the problem is that it would be breaking, unless we add a new method, like optionalQueryParam?

beng9re added a commit to beng9re/rest-assured that referenced this issue Mar 18, 2024
rest-assured#1751
If this QueryParam value is null, no query parameter is added
If not null, the query parameter is added with the given parameter name and value.
@beng9re
Copy link

beng9re commented Mar 18, 2024

I opened a PR (#1776) to implement the functionality described in that part.

@injae-kim
Copy link

optionalQueryParam() will be so useful to many users include me :)

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

No branches or pull requests

4 participants