From 27c22061c5a2817fbd50d68571dbb0576b87877a Mon Sep 17 00:00:00 2001 From: Dennis <16547088+soligen2010@users.noreply.github.com> Date: Fri, 3 May 2024 12:38:34 -0400 Subject: [PATCH] Fix for BaseUrl in base class not being used Fix to use the BaseUrl from the base class when there is a base class and GenerateBaseUrlProperty is not set. --- .../Templates/Client.Class.liquid | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid b/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid index d774f0c82e..a1c03f3bae 100644 --- a/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid +++ b/src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid @@ -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 @@ -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 }}"; @@ -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: "{" -%}