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: C# Code Generation generates method with return default(void) #4826

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ public string MethodAccessModifier
/// <summary>
/// The default value of the result type, i.e. default(T) or default(T)! depending on whether NRT are enabled.
/// </summary>
public string UnwrappedResultDefaultValue => $"default({UnwrappedResultType}){((_settings as CSharpClientGeneratorSettings)?.CSharpGeneratorSettings.GenerateNullableReferenceTypes == true ? "!" : "")}";
public string UnwrappedResultDefaultValue => HasResult
? $"default({UnwrappedResultType}){((_settings as CSharpClientGeneratorSettings)?.CSharpGeneratorSettings.GenerateNullableReferenceTypes == true ? "!" : "")}"
: null;

/// <summary>Gets or sets the synchronous type of the result.</summary>
public string SyncResultType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ throw new {{ ExceptionClass }}<{{ response.Type }}>("{{ response.ExceptionDescri
{% if operation.WrapResponse -%}
return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>(status_, headers_, {{ operation.UnwrappedResultDefaultValue }});
{% else -%}
return {{ operation.UnwrappedResultDefaultValue }};
{% if operation.HasResult %}return {{ operation.UnwrappedResultDefaultValue }};{% else %}return;{% endif %}
{% endif -%}
{% else -%}
{% if operation.WrapResponse -%}
Expand Down
4 changes: 2 additions & 2 deletions src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@
{% if operation.WrapResponse and operation.UnwrappedResultType != "FileResponse" %}
return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>(status_, headers_, {{ operation.UnwrappedResultDefaultValue }});
{% else -%}
return {{ operation.UnwrappedResultDefaultValue }};
{% if operation.HasResult %}return {{ operation.UnwrappedResultDefaultValue }};{% else %}return;{% endif %}
{% endif -%}
{% elsif operation.WrapResponse -%}
return new {{ ResponseClass }}(status_, headers_);
Expand All @@ -425,7 +425,7 @@
{% if operation.WrapResponse and operation.UnwrappedResultType != "FileResponse" %}
return new {{ ResponseClass }}<{{ operation.UnwrappedResultType }}>(status_, headers_, {{ operation.UnwrappedResultDefaultValue }});
{% else -%}
return {{ operation.UnwrappedResultDefaultValue }};
{% if operation.HasResult %}return {{ operation.UnwrappedResultDefaultValue }};{% else %}return;{% endif %}
{% endif -%}
{% elsif operation.WrapResponse -%}
return new {{ ResponseClass }}(status_, headers_);
Expand Down
Loading