Skip to content

Commit

Permalink
Fix for BaseUrl in base class not being used
Browse files Browse the repository at this point in the history
Fix to use the BaseUrl from the base class when there is a base class and GenerateBaseUrlProperty is not set.
  • Loading branch information
soligen2010 committed May 3, 2024
1 parent 6b49eef commit 27c2206
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[System.CodeDom.Compiler.GeneratedCode("NSwag", "{{ ToolchainVersion }}")]
{{ ClientClassAccessModifier }} partial class {{ Class }} {% if HasBaseType %}: {% endif %}{% if HasBaseClass %}{{ BaseClass }}{% if GenerateClientInterfaces %}, {% endif %}{% endif %}{% if GenerateClientInterfaces %}I{{ Class }}{% endif %}
{
{% if UseBaseUrl -%}
{% if UseBaseUrl and HasBaseClass == false and GenerateBaseUrlProperty == true -%}
#pragma warning disable 8618
private string _baseUrl;
#pragma warning restore 8618
Expand Down Expand Up @@ -34,7 +34,7 @@
public {{ Class }}({{ constructorParameters }}){% if HasConfigurationClass and HasBaseClass -%}{{ " : base(configuration)"}}{% endif %}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
{
{% if UseBaseUrl -%}
{% if UseBaseUrl and HasBaseClass == false and GenerateBaseUrlProperty == true -%}
{% if HasBaseUrl -%}
{% if GenerateBaseUrlProperty -%}
BaseUrl = "{{ BaseUrl }}";
Expand Down Expand Up @@ -290,7 +290,11 @@
{% endif -%}

var urlBuilder_ = new System.Text.StringBuilder();
{% if UseBaseUrl %}if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);{% endif %}
{% if HasBaseClass == true and GenerateBaseUrlProperty == false -%}
if (!string.IsNullOrEmpty(BaseUrl)) urlBuilder_.Append(BaseUrl);
{% else -%}
if (!string.IsNullOrEmpty(_baseUrl)) urlBuilder_.Append(_baseUrl);
{% endif -%}
// Operation Path: "{{ operation.Path }}"
{% if operation.Path contains "{" -%}
{% assign pathParts = operation.Path | split: "{" -%}
Expand Down

0 comments on commit 27c2206

Please sign in to comment.