refit icon indicating copy to clipboard operation
refit copied to clipboard

[Bug]: Nullable collections parameters malformed

Open 304NotModified opened this issue 2 years ago • 1 comments

Describe the bug 🐞

For collections with nullable types, (e.g. int?[]), the parameters aren't correctly rendered to the URL

Step to reproduce

Given:

[Get("/api/resource1/")]
Task<IApiResponse<GetRentetabelResponse>> TestCall2([Query(CollectionFormat.Csv)] IEnumerable<int?> numbers);

and test

[Fact]
public async Task TestCall2()
{
    // Arrange
    var numbers = new int?[] { 23 };

    // Act
    var result = await _sut.TestCall2(numbers);

    // Assert
    result.RequestMessage?.RequestUri.Should().Be("https://github.com/api/resource1/?numbers=23");

}

Reproduction repository

https://github.com/reactiveui/refit

Expected behavior

I've expect: https://github.com/api/resource1/?numbers=23 But I get: https://github.com/api/resource1/?Length=1&LongLength=1&Rank=1&SyncRoot=23&IsReadOnly=False&IsFixedSize=True&IsSynchronized=False

Note, it does work when I have int instead of int?:

[Get("/api/resource1/")]
Task<IApiResponse<GetRentetabelResponse>> TestCall([Query(CollectionFormat.Csv)] IEnumerable<int> numbers);
  • With or without [Query(CollectionFormat.Csv)] gives the same result

Screenshots 🖼️

No response

IDE

No response

Operating system

No response

Version

No response

Device

No response

Refit Version

Tested with 6.5.1 and 7.0.0 - same behavior

Additional information ℹ️

related; https://github.com/reactiveui/refit/issues/432, #687

304NotModified avatar Sep 25 '23 15:09 304NotModified

Note: I tried to fix this with a custom UrlParameterFormatter, but I get with Format already the values 1, true and false (those of SyncRoot, Length etc)

304NotModified avatar Sep 25 '23 15:09 304NotModified