Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,21 @@ namespace {{packageName}}.{{apiPackage}}
{
private JsonSerializerOptions _jsonSerializerOptions;

private readonly string[] _contentHeaders =
[
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Moved to ClientUtils

"allow",
"content-encoding",
"content-language",
"content-length",
"content-location",
"content-md5",
"content-range",
"content-type",
"expires",
"last-modified",
"extension-header"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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>
Expand Down Expand Up @@ -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}}
Expand Down Expand Up @@ -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)
Copy link
Copy Markdown
Contributor

@devhl-labs devhl-labs Apr 22, 2026

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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));
}
Comment thread
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>();
Expand Down Expand Up @@ -907,4 +974,4 @@ namespace {{packageName}}.{{apiPackage}}
}
{{/operations}}
}
{{/lambda.trimLineBreaks}}
{{/lambda.trimLineBreaks}}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ public sealed partial class DefaultApi : IDefaultApi
{
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"
];

/// <summary>
/// The logger factory
/// </summary>
Expand Down Expand Up @@ -249,9 +264,16 @@ public async Task<IHelloWorldPostApiResponse> HelloWorldPostAsync(Option<HelloWo
: string.Concat(HttpClient.BaseAddress.AbsolutePath.TrimEnd('/'), "/helloWorld");

if (helloWorldPostRequest.IsSet)
httpRequestMessageLocalVar.Content = (helloWorldPostRequest.Value as object) is System.IO.Stream stream
? httpRequestMessageLocalVar.Content = new StreamContent(stream)
: httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize(helloWorldPostRequest.Value, _jsonSerializerOptions));
{
if ((helloWorldPostRequest.Value as object) is System.IO.Stream stream)
{
httpRequestMessageLocalVar.Content = new StreamContent(stream);
}
else
{
httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize(helloWorldPostRequest.Value, _jsonSerializerOptions));
}
}

httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public sealed partial class DefaultApi : IDefaultApi
{
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"
];

/// <summary>
/// The logger factory
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public sealed partial class DefaultApi : IDefaultApi
{
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"
];

/// <summary>
/// The logger factory
/// </summary>
Expand Down Expand Up @@ -230,9 +245,16 @@ public async Task<IOneOfArrayApiResponse> OneOfArrayAsync(Option<OneOfArrayReque
: string.Concat(HttpClient.BaseAddress.AbsolutePath.TrimEnd('/'), "/one-of-array");

if (oneOfArrayRequest.IsSet)
httpRequestMessageLocalVar.Content = (oneOfArrayRequest.Value as object) is System.IO.Stream stream
? httpRequestMessageLocalVar.Content = new StreamContent(stream)
: httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize(oneOfArrayRequest.Value, _jsonSerializerOptions));
{
if ((oneOfArrayRequest.Value as object) is System.IO.Stream stream)
{
httpRequestMessageLocalVar.Content = new StreamContent(stream);
}
else
{
httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize(oneOfArrayRequest.Value, _jsonSerializerOptions));
}
}

httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public sealed partial class APIKEYSApi : IAPIKEYSApi
{
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"
];

/// <summary>
/// The logger factory
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ public sealed partial class APIKeysApi : IAPIKeysApi
{
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"
];

/// <summary>
/// The logger factory
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,21 @@ public sealed partial class ApiKeysApi : IApiKeysApi
{
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"
];

/// <summary>
/// The logger factory
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,21 @@ public sealed partial class AnotherFakeApi : IAnotherFakeApi
{
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"
];

/// <summary>
/// The logger factory
/// </summary>
Expand Down Expand Up @@ -277,9 +292,14 @@ public async Task<ICall123TestSpecialTagsApiResponse> Call123TestSpecialTagsAsyn
? "/another-fake/dummy"
: string.Concat(HttpClient.BaseAddress.AbsolutePath.TrimEnd('/'), "/another-fake/dummy");

httpRequestMessageLocalVar.Content = (modelClient as object) is System.IO.Stream stream
? httpRequestMessageLocalVar.Content = new StreamContent(stream)
: httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize(modelClient, _jsonSerializerOptions));
if ((modelClient as object) is System.IO.Stream stream)
{
httpRequestMessageLocalVar.Content = new StreamContent(stream);
}
else
{
httpRequestMessageLocalVar.Content = new StringContent(JsonSerializer.Serialize(modelClient, _jsonSerializerOptions));
}

httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,21 @@ public sealed partial class DefaultApi : IDefaultApi
{
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"
];

/// <summary>
/// The logger factory
/// </summary>
Expand Down
Loading