Skip to content

Commit

Permalink
Omit null query parameters in generated http client (Breaks compatibi…
Browse files Browse the repository at this point in the history
…lity with ASP.NET WebApi because query arguments are part of the routing selection)
  • Loading branch information
C0nquistadore committed Jun 2, 2024
1 parent 60cd43a commit caa74b8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Dibix.Http.Client/Client/UriBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private UriBuilder(string url, UriKind kind)

public UriBuilder AddQueryParam<T>(string name, T value) where T : struct => this.AddQueryParam(name, ToString(value));
public UriBuilder AddQueryParam<T>(string name, T value, T defaultValue) where T : struct => !Equals(value, defaultValue) ? AddQueryParam(name, ToString(value)) : this;
public UriBuilder AddQueryParam<T>(string name, T? value) where T : struct => this.AddQueryParam(name, ToString(value));
public UriBuilder AddQueryParam<T>(string name, T? value) where T : struct => value != null ? AddQueryParam(name, ToString(value)) : this;
public UriBuilder AddQueryParam<T>(string name, T? value, T? defaultValue) where T : struct => !Equals(value, defaultValue) ? AddQueryParam(name, ToString(value)) : this;
public UriBuilder AddQueryParam(string name, string value)
{
Expand Down
7 changes: 4 additions & 3 deletions tests/Dibix.Http.Client.Tests/UriBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public void CrossCheck()
{
Uri uri = UriBuilder.Create("some/kind/{of}/uri", UriKind.Relative)
.AddQueryParam("name", "luke")
.AddQueryParam("id", (int?)null)
.AddQueryParam("omitnull", (int?)null, null)
.AddQueryParam("omitprimitive", 3, 3)
.AddQueryParam("id", "")
.AddQueryParam("omitnull", (int?)null)
.AddQueryParam("omitdefaultnull", (int?)null, null)
.AddQueryParam("omitdefaultprimitive", 3, 3)
.AddQueryParam("bool", true)
.AddQueryParam("array", "first")
.AddQueryParam("array", "second")
Expand Down

0 comments on commit caa74b8

Please sign in to comment.