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

Fix unwanted query parameter explosion in generated c# client #4310

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

burgmanna
Copy link

Per default NSwag ignores if array parameters should be exploded or not.

So as of now a request containing multiple IDs generates the following:
/users?id=3&id=4&id=5

As per specification we do not want to specify the parameter name every time in case explode is set to false.
Instead we expect /users?id=3,4,5.

@burgmanna burgmanna closed this Jan 11, 2023
@burgmanna burgmanna reopened this Jan 11, 2023
@paulcurren
Copy link

Note: this doesn't fix the OpenApi 2.0 variant:
"collectionFormat": "csv",

@@ -6,8 +6,13 @@ foreach (var item_ in {{ parameter.VariableName }}) { urlBuilder_.Append(System.
urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}") + "=").Append(System.Uri.EscapeDataString({% if parameter.IsNullable and parameter.IsRequired %}{{ parameter.VariableName }} != null ? {% endif %}{{ parameter.VariableName }}{% if parameter.IsSystemNullable %}.Value{% endif %}.ToString("{{ ParameterDateTimeFormat }}", System.Globalization.CultureInfo.InvariantCulture){% if parameter.IsNullable and parameter.IsRequired %} : "{{ QueryNullValue }}"{% endif %})).Append("&");
{% elsif parameter.IsDate -%}
urlBuilder_.Append(System.Uri.EscapeDataString("{{ parameter.Name }}") + "=").Append(System.Uri.EscapeDataString({% if parameter.IsNullable and parameter.IsRequired %}{{ parameter.VariableName }} != null ? {% endif %}{{ parameter.VariableName }}{% if parameter.IsSystemNullable %}.Value{% endif %}.ToString("{{ ParameterDateFormat }}", System.Globalization.CultureInfo.InvariantCulture){% if parameter.IsNullable and parameter.IsRequired %} : "{{ QueryNullValue }}"{% endif %})).Append("&");
{% elsif parameter.IsArray -%}
{% elsif parameter.IsArray and parameter.Explode == true -%}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also test for "collectionFormat": "csv",

@Mapel
Copy link

Mapel commented Sep 25, 2024

Hey, can this pull request be considered for merging in near future? This bug is already quite old and it is an easy fix.

@Eldriann
Copy link

Eldriann commented Oct 7, 2024

Hey, are any changes needed for this PR?
I also encountered this case today, and this code seems to resolve the issue. I'm using the templateDirectory parameter to temporarily override the file, but it would be a great bug fix to merge.

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

Successfully merging this pull request may close these issues.

5 participants