From 2199c99d8334a370f0cf860842d31c423d6c7ac2 Mon Sep 17 00:00:00 2001 From: Tommy Date: Wed, 5 Jun 2024 21:08:12 +0200 Subject: [PATCH] Revert "Omit null query parameters in generated http client (Breaks compatibility with ASP.NET WebApi because query arguments are part of the routing selection)" This reverts commit caa74b85f74ab67f3beb8af3c36a05a0ff8452d0. --- src/Dibix.Http.Client/Client/UriBuilder.cs | 2 +- tests/Dibix.Http.Client.Tests/UriBuilderTest.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Dibix.Http.Client/Client/UriBuilder.cs b/src/Dibix.Http.Client/Client/UriBuilder.cs index 1e2b64a5..c12d35dd 100644 --- a/src/Dibix.Http.Client/Client/UriBuilder.cs +++ b/src/Dibix.Http.Client/Client/UriBuilder.cs @@ -23,7 +23,7 @@ private UriBuilder(string url, UriKind kind) public UriBuilder AddQueryParam(string name, T value) where T : struct => this.AddQueryParam(name, ToString(value)); public UriBuilder AddQueryParam(string name, T value, T defaultValue) where T : struct => !Equals(value, defaultValue) ? AddQueryParam(name, ToString(value)) : this; - public UriBuilder AddQueryParam(string name, T? value) where T : struct => value != null ? AddQueryParam(name, ToString(value)) : this; + public UriBuilder AddQueryParam(string name, T? value) where T : struct => this.AddQueryParam(name, ToString(value)); public UriBuilder AddQueryParam(string name, T? value, T? defaultValue) where T : struct => !Equals(value, defaultValue) ? AddQueryParam(name, ToString(value)) : this; public UriBuilder AddQueryParam(string name, string value, string defaultValue) => !Equals(value, defaultValue) ? AddQueryParam(name, ToString(value)) : this; public UriBuilder AddQueryParam(string name, string value) diff --git a/tests/Dibix.Http.Client.Tests/UriBuilderTest.cs b/tests/Dibix.Http.Client.Tests/UriBuilderTest.cs index bf4b2abf..2f982291 100644 --- a/tests/Dibix.Http.Client.Tests/UriBuilderTest.cs +++ b/tests/Dibix.Http.Client.Tests/UriBuilderTest.cs @@ -11,8 +11,7 @@ public void CrossCheck() { Uri uri = UriBuilder.Create("some/kind/{of}/uri", UriKind.Relative) .AddQueryParam("name", "luke") - .AddQueryParam("id", "") - .AddQueryParam("omitnull", (int?)null) + .AddQueryParam("id", (int?)null) .AddQueryParam("omitdefaultnullint", (int?)null, null) .AddQueryParam("omitdefaultnullstring", (string?)null, null) .AddQueryParam("omitdefaultprimitive", 3, 3)