-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Fix/csharp reserved headers and file parameter not serialising correctly #23593
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
44a20ed
78b3384
b7eee79
7f890c1
210df50
99fbc55
dd199ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -160,6 +160,21 @@ namespace {{packageName}}.{{apiPackage}} | |
| { | ||
| private JsonSerializerOptions _jsonSerializerOptions; | ||
|
|
||
| private readonly string[] _contentHeaders = | ||
| [ | ||
| "allow", | ||
| "content-encoding", | ||
| "content-language", | ||
| "content-length", | ||
| "content-location", | ||
| "content-md5", | ||
| "content-range", | ||
| "content-type", | ||
| "expires", | ||
| "last-modified", | ||
| "extension-header" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot is telling me extension-header is demonstrating the format, but isn't a real entry. Consider removing it. I'd also appreciate if you remove the spaces that appear after these values. |
||
| ]; | ||
|
|
||
| /// <summary> | ||
| /// The logger factory | ||
| /// </summary> | ||
|
|
@@ -452,23 +467,6 @@ namespace {{packageName}}.{{apiPackage}} | |
|
|
||
| {{/-last}} | ||
| {{/queryParams}} | ||
| {{#constantParams}} | ||
| {{#isHeaderParam}} | ||
| // Set client side default value of Header Param "{{baseName}}". | ||
| httpRequestMessageLocalVar.Headers.Add("{{baseName}}", ClientUtils.ParameterToString({{#_enum}}"{{{.}}}"{{/_enum}})); // Constant header parameter | ||
| {{/isHeaderParam}} | ||
| {{/constantParams}} | ||
| {{#headerParams}} | ||
| {{#required}} | ||
| httpRequestMessageLocalVar.Headers.Add("{{baseName}}", ClientUtils.ParameterToString({{paramName}})); | ||
|
|
||
| {{/required}} | ||
| {{^required}} | ||
| if ({{paramName}}.IsSet) | ||
| httpRequestMessageLocalVar.Headers.Add("{{baseName}}", ClientUtils.ParameterToString({{paramName}}.Value)); | ||
|
|
||
| {{/required}} | ||
| {{/headerParams}} | ||
| {{#formParams}} | ||
| {{#-first}} | ||
| {{#isMultipart}} | ||
|
|
@@ -561,18 +559,87 @@ namespace {{packageName}}.{{apiPackage}} | |
| {{/formParams}} | ||
| {{#bodyParam}} | ||
| {{#required}} | ||
| httpRequestMessageLocalVar.Content = ({{paramName}}{{^required}}.Value{{/required}} as object) is System.IO.Stream stream | ||
| ? httpRequestMessageLocalVar.Content = new StreamContent(stream) | ||
| : httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize({{paramName}}{{^required}}.Value{{/required}}, _jsonSerializerOptions)); | ||
| if (({{paramName}}{{^required}}.Value{{/required}} as object) is System.IO.Stream stream) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In generichost I don't believe it will ever be a System.IO.Stream anymore, I think its always going to be a FileParameter. Im not positive though. Worth looking into. You can leave this alone if you want though. edit - I had copilot check and despite the type mapping being a Stream, the templates actually use FileParameter, so it should be safe to remove.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
| { | ||
| httpRequestMessageLocalVar.Content = new StreamContent(stream); | ||
| } | ||
| {{#isFile}} | ||
| else if (({{paramName}}{{^required}}.Value{{/required}} as object) is {{packageName}}.{{clientPackage}}.FileParameter fileParameterLocalVar) | ||
| { | ||
| httpRequestMessageLocalVar.Content = new StreamContent(fileParameterLocalVar.Content); | ||
| } | ||
| {{/isFile}} | ||
| else | ||
| { | ||
| httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize({{paramName}}{{^required}}.Value{{/required}}, _jsonSerializerOptions)); | ||
| } | ||
| {{/required}} | ||
| {{^required}} | ||
| if ({{paramName}}.IsSet) | ||
| httpRequestMessageLocalVar.Content = ({{paramName}}{{^required}}.Value{{/required}} as object) is System.IO.Stream stream | ||
| ? httpRequestMessageLocalVar.Content = new StreamContent(stream) | ||
| : httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize({{paramName}}{{^required}}.Value{{/required}}, _jsonSerializerOptions)); | ||
| { | ||
| if (({{paramName}}{{^required}}.Value{{/required}} as object) is System.IO.Stream stream) | ||
| { | ||
| httpRequestMessageLocalVar.Content = new StreamContent(stream); | ||
| } | ||
| {{#isFile}} | ||
| else if (({{paramName}}{{^required}}.Value{{/required}} as object) is {{packageName}}.{{clientPackage}}.FileParameter fileParameterLocalVar) | ||
| { | ||
| httpRequestMessageLocalVar.Content = new StreamContent(fileParameterLocalVar.Content); | ||
| } | ||
| {{/isFile}} | ||
| else | ||
| { | ||
| httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize({{paramName}}{{^required}}.Value{{/required}}, _jsonSerializerOptions)); | ||
| } | ||
| } | ||
| {{/required}} | ||
|
|
||
| {{/bodyParam}} | ||
|
|
||
| {{#constantParams}} | ||
| {{#isHeaderParam}} | ||
| // Set client side default value of Header Param "{{baseName}}". | ||
| if (_contentHeaders.Contains("{{baseName}}".ToLowerInvariant())) | ||
| { | ||
| httpRequestMessageLocalVar.Content.Headers.Add("{{baseName}}", ClientUtils.ParameterToString({{#_enum}}"{{{.}}}"{{/_enum}})); // Constant header parameter | ||
| } | ||
| else | ||
| { | ||
| httpRequestMessageLocalVar.Headers.Add("{{baseName}}", ClientUtils.ParameterToString({{#_enum}}"{{{.}}}"{{/_enum}})); // Constant header parameter | ||
| } | ||
|
|
||
| {{/isHeaderParam}} | ||
| {{/constantParams}} | ||
| {{#headerParams}} | ||
| {{#required}} | ||
| // Set client side default value of Header Param "{{baseName}}". | ||
| if (_contentHeaders.Contains("{{baseName}}".ToLowerInvariant())) | ||
| { | ||
| httpRequestMessageLocalVar.Content.Headers.Add("{{baseName}}", ClientUtils.ParameterToString({{paramName}})); | ||
| } | ||
| else | ||
| { | ||
| httpRequestMessageLocalVar.Headers.Add("{{baseName}}", ClientUtils.ParameterToString({{paramName}})); | ||
| } | ||
|
|
||
| {{/required}} | ||
| {{^required}} | ||
| if ({{paramName}}.IsSet) | ||
| { | ||
| // Set client side default value of Header Param "{{baseName}}". | ||
| if (_contentHeaders.Contains("{{baseName}}".ToLowerInvariant())) | ||
| { | ||
| httpRequestMessageLocalVar.Content.Headers.Add("{{baseName}}", ClientUtils.ParameterToString({{paramName}}.Value)); | ||
| } | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| else | ||
| { | ||
| httpRequestMessageLocalVar.Headers.Add("{{baseName}}", ClientUtils.ParameterToString({{paramName}}.Value)); | ||
| } | ||
| } | ||
|
|
||
| {{/required}} | ||
| {{/headerParams}} | ||
|
|
||
| {{#authMethods}} | ||
| {{#-first}} | ||
| List<TokenBase> tokenBaseLocalVars = new List<TokenBase>(); | ||
|
|
@@ -907,4 +974,4 @@ namespace {{packageName}}.{{apiPackage}} | |
| } | ||
| {{/operations}} | ||
| } | ||
| {{/lambda.trimLineBreaks}} | ||
| {{/lambda.trimLineBreaks}} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making this static readonly, or move it to ClientUtils.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to ClientUtils