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("{\"first\":true}", firstParams.ToString(Formatting.None));
|
||||||
Assert.AreEqual("{\"second\":false}", secondParams.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
|
public class FirstRequestModel : RequestParams
|
||||||
@ -51,4 +60,10 @@ namespace SpotifyAPI.Web.Tests
|
|||||||
[QueryParam("second")]
|
[QueryParam("second")]
|
||||||
public bool? Second { get; set; }
|
public bool? Second { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class EmptyListExampleRequestModel : RequestParams
|
||||||
|
{
|
||||||
|
[QueryParam("list")]
|
||||||
|
public IList<string> List { get; set; } = new List<string>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,10 +97,13 @@ namespace SpotifyAPI.Web
|
|||||||
object value = prop.GetValue(this);
|
object value = prop.GetValue(this);
|
||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
if (value is IList<string> list && list.Count > 0)
|
if (value is IList<string> list)
|
||||||
{
|
{
|
||||||
var str = string.Join(",", list);
|
if (list.Count > 0)
|
||||||
queryParams.Add(attribute.Key ?? prop.Name, str);
|
{
|
||||||
|
var str = string.Join(",", list);
|
||||||
|
queryParams.Add(attribute.Key ?? prop.Name, str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (value is bool valueAsBool)
|
else if (value is bool valueAsBool)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user