quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.82k stars 2.69k forks source link

Support optional @QueryParam on Rest client #42623

Open diversit opened 3 months ago

diversit commented 3 months ago

Description

The Quarkus Rest client does not seem to support @QueryParam arguments which are of type java.util.Optional or io.vavr.control.Option.

Using an argument like @QueryParam("type") Optional<String> or @QueryParam("type") Option<String> creates a url like http://myhost/endpoint?type=Optional%5Btype%5D or http://myhost/endpoint?type=Some%28type%29. Or with ?type=Optional.empty or ?type=None when no value is provided.

Currently the only option to have optional query parameters seems to be to use a @RestQuery Map<String, String> queryParams argument. This however do not give a strict control on which query parameters are allowed.

It would therefore be nice to support Optional and/or Option argument to have a better typed and documented Rest client function.

Implementation ideas

Support java.util.Optional as @QueryParam arguments. When a value is provided, add it to the query parameters. When no value is provided, do not add it to the query parameters.

And it would be awesome when also Vavr's io.vavr.control.Option could be supported.

quarkus-bot[bot] commented 3 months ago

/cc @cescoffier (rest-client), @geoand (rest-client)

geoand commented 2 months ago

We can definitely support Optional, but I am afraid we that we are not going to introduce any kind of support for Vavr.