Skip to content
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

Action.Url does not support array-valued parameters #116

Closed
Ackhuman opened this issue May 24, 2024 · 1 comment · Fixed by #124
Closed

Action.Url does not support array-valued parameters #116

Ackhuman opened this issue May 24, 2024 · 1 comment · Fixed by #124
Assignees

Comments

@Ackhuman
Copy link

Ackhuman commented May 24, 2024

I have an API method with the following signature:

IEnumerable<DataSeries> GetDashboardChart(string stateAbbr, [FromUri]string[] varNames)

The URL GetDashboardChart?stateAbbr=&varNames=VAR1&varNames=VAR2 should result in a valid query to this method. However, there is no support for this in Action.Url. I have written a custom function to handle this case:

    public static string GetArrayQueryParams(IMethod method)
    {
        var arrayParameters = new List<string>();
        foreach (var parameter in method.Parameters)
        {
            if (parameter.Type.IsCollection && !parameter.HasAttribute("FromBody"))
            {
                arrayParameters.Add($"${{{parameter.Name}.map(item => `{parameter.Name}=${{item}}`).join('&')}}");
            }
        }
        return arrayParameters.Any() ? $"&{string.Join("&", arrayParameters)}" : string.Empty;
    }

Which results in the following TypeScript:

&${varNames.map(item => `varNames=${item}`).join('&')}

This works, but it would be better if this were built-in functionality.

@NeVeSpl
Copy link
Owner

NeVeSpl commented May 30, 2024

Fell free to prepare PR with that functionality, just remember to include appropriate tests for it.

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