Skip to content

Code generated by NSwag.ApiDescription.Client 14.4.0 generates incorrect URLs #5165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rainerbossert opened this issue May 7, 2025 · 4 comments

Comments

@rainerbossert
Copy link

Describe the bug

Code generated with NSwag.ApiDescription.Client 14.4.0 generates urls with enumerable int parameters a way that the standard WebApi model binder cannot handle.

using System.Globalization;

var builder144 = new System.Text.StringBuilder();

int[]? fundingSchemeIds = { 1, 2, 3 };

if (fundingSchemeIds != null)
{
    builder144.Append(System.Uri.EscapeDataString("FundingSchemeIds") + "=");
    foreach (var item_ in fundingSchemeIds)
    {
        builder144.Append(System.Uri.EscapeDataString(ConvertToString(item_, System.Globalization.CultureInfo.InvariantCulture))).Append(",");
    }
    builder144.Length--;
    builder144.Append("&");
}

Console.WriteLine("{0} // 14.4.0", builder144);

var builder143 = new System.Text.StringBuilder();

if (fundingSchemeIds != null)
{
    foreach (var item_ in fundingSchemeIds) { builder143.Append(System.Uri.EscapeDataString("FundingSchemeIds")).Append('=').Append(System.Uri.EscapeDataString(ConvertToString(item_, System.Globalization.CultureInfo.InvariantCulture))).Append('&'); }
}


Console.WriteLine("{0} // 14.3.0", builder143);
Console.Read();

string ConvertToString(int i, CultureInfo cultureInfo)
{
    return $"{i}";
}

Output

FundingSchemeIds=1,2,3& // 14.4.0 --> nok
FundingSchemeIds=1&FundingSchemeIds=2&FundingSchemeIds=3& // 14.3.0 --> ok

While the endpoint looks like

    [HttpGet(Name = nameof(SearchGrantsAsync))]
    [AllowAnonymous]
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
    [ProducesResponseType(typeof(SearchResult), StatusCodes.Status200OK)]
    public async Task<ActionResult<SearchResult>> SearchGrantsAsync([FromQuery] IEnumerable<int> fundingSchemeIds, CancellationToken cancellationToken)

Somehow similar to: #5096 (but the version 14.2.0 seems off).

Version of NSwag toolchain, computer and .NET runtime used

Nuget package NSwag.ApiDescription.Client --version 14.4.0

To Reproduce

Visual Studio 2022 (Version 17.13.6) right click on project using the service > Add > Connected Service > Service References > (Existing) Refresh

Expected behavior

The url generated in the client still works as it did before in Version 14.3.0

@rainerbossert rainerbossert changed the title Code generated by NSwag.ApiDescription.Client generates incorrect URLs Code generated by NSwag.ApiDescription.Client 14.4.0 generates incorrect URLs May 7, 2025
@alexfirs
Copy link

alexfirs commented May 7, 2025

caused by #5016 - is not backward compatible unfortunately

@bifa-zuehlke
Copy link

The query format FundingSchemeIds=1,2,3 does not correctly bind to IEnumerable fundingSchemeIds in ASP.NET Core (.NET 6+). The default model binder expects repeated parameters like FundingSchemeIds=1&FundingSchemeIds=2&FundingSchemeIds=3 for correct binding.

How should we handle this @alexfirs?

@alexfirs
Copy link

alexfirs commented May 8, 2025

@bifa-zuehlke i temporary downgraded to 14.2 until it fixed

@ThomasTosik
Copy link

We found out the same issue. This is extremely breaking. Makes the generated C# clients useless because MS want it done differently as described by bifa-zuehlke.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants