mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 14:46:26 +00:00
Empty lists are correctly excluded from query params, fixes #471
This commit is contained in:
parent
a15e71c815
commit
27773caa28
@ -36,6 +36,15 @@ namespace SpotifyAPI.Web.Tests
|
||||
Assert.AreEqual("{\"first\":true}", firstParams.ToString(Formatting.None));
|
||||
Assert.AreEqual("{\"second\":false}", secondParams.ToString(Formatting.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmptyListIsSkippedInQueryParams()
|
||||
{
|
||||
var first = new EmptyListExampleRequestModel();
|
||||
Assert.AreEqual(new Dictionary<string, string> { }, first.BuildQueryParams());
|
||||
first.List.Add("hello_world");
|
||||
Assert.AreEqual(new Dictionary<string, string> { { "list", "hello_world" } }, first.BuildQueryParams());
|
||||
}
|
||||
}
|
||||
|
||||
public class FirstRequestModel : RequestParams
|
||||
@ -51,4 +60,10 @@ namespace SpotifyAPI.Web.Tests
|
||||
[QueryParam("second")]
|
||||
public bool? Second { get; set; }
|
||||
}
|
||||
|
||||
public class EmptyListExampleRequestModel : RequestParams
|
||||
{
|
||||
[QueryParam("list")]
|
||||
public IList<string> List { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
@ -97,11 +97,14 @@ namespace SpotifyAPI.Web
|
||||
object value = prop.GetValue(this);
|
||||
if (value != null)
|
||||
{
|
||||
if (value is IList<string> list && list.Count > 0)
|
||||
if (value is IList<string> list)
|
||||
{
|
||||
if (list.Count > 0)
|
||||
{
|
||||
var str = string.Join(",", list);
|
||||
queryParams.Add(attribute.Key ?? prop.Name, str);
|
||||
}
|
||||
}
|
||||
else if (value is bool valueAsBool)
|
||||
{
|
||||
queryParams.Add(attribute.Key ?? prop.Name, valueAsBool ? "true" : "false");
|
||||
|
Loading…
Reference in New Issue
Block a user