Skip to content

Commit

Permalink
Fix missing assignment of base URL
Browse files Browse the repository at this point in the history
Fixes #4637
  • Loading branch information
paulomorgado committed Jan 8, 2024
1 parent 4d0e6a6 commit dfec161
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions src/NSwag.CodeGeneration.CSharp/Templates/Client.Class.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,51 @@
private static System.Lazy<{{ JsonSerializerSettingsType }}> _settings = new System.Lazy<{{ JsonSerializerSettingsType }}>(CreateSerializerSettings, true);
{% endif -%}

{% assign constructorParameters = "" -%}
{% if HasConfigurationClass -%}
public {{ Class }}({{ ConfigurationClass }} configuration{% if InjectHttpClient %}, {{ HttpClientType }} httpClient{% endif %}) : base(configuration)
{
{% if InjectHttpClient -%}
_httpClient = httpClient;
{% endif -%}
{% elsif UseBaseUrl and HasBaseUrl == false %}
public {{ Class }}(string baseUrl{% if InjectHttpClient %}, {{ HttpClientType }} httpClient{% endif %})
{% assign constructorParameters = ConfigurationClass | append: " configuration" -%}
{% endif -%}
{% if UseBaseUrl and HasBaseUrl == false and HasConfigurationClass == false -%}
{% unless constructorParameters == "" -%}{% assign constructorParameters = constructorParameters | append: ", " -%}{% endunless -%}
{% assign constructorParameters = constructorParameters | append: "string baseUrl" -%}
{% endif -%}
{% if InjectHttpClient -%}
{% unless constructorParameters == "" -%}{% assign constructorParameters = constructorParameters | append: ", " -%}{% endunless -%}
{% assign constructorParameters = constructorParameters | append: HttpClientType | append: " httpClient" -%}
{% endif -%}
public {{ Class }}({{ constructorParameters }}){% if HasConfigurationClass and HasBaseClass -%}{{ " : base(configuration)"}}{% endif %}
{
{% if UseBaseUrl -%}
{% if HasBaseUrl -%}
{% if GenerateBaseUrlProperty -%}
BaseUrl = "{{ BaseUrl }}";
{% else -%}
{% if BaseUrl != "" -%}
{% assign baseUrlLength = BaseUrl | size -%}
{% assign lastUrlCharIndex = baseUrlLength | minus: 1 -%}
{% assign lastUrlChar = BaseUrl | slice: lastUrlCharIndex, 1 -%}
{% if lastUrlChar == "/" -%}
_baseUrl = "{{ BaseUrl }}";
{% else -%}
_baseUrl = "{{ BaseUrl }}/";
{% endif -%}
{% endif -%}
{% endif -%}
{% else -%}
{% if GenerateBaseUrlProperty -%}
BaseUrl = baseUrl;
{% if InjectHttpClient -%}
_httpClient = httpClient;
{% else -%}
{% if HasConfigurationClass == false -%}
_baseUrl = (string.IsNullOrEmpty(baseUrl) || baseUrl.EndsWith("/"))
? baseUrl
: baseUrl + "/";
{% endif -%}
{% endif -%}
{% endif -%}
{% endif -%}
{% elsif InjectHttpClient %}
public {{ Class }}({{ HttpClientType }} httpClient)
{
{% if InjectHttpClient -%}
_httpClient = httpClient;
{% else -%}
public {{ Class }}()
{
{% if UseBaseUrl and GenerateBaseUrlProperty -%}
BaseUrl = "{{ BaseUrl }}";
{% endif -%}
{% endif -%}
{% template Client.Class.Constructor %}
}

Expand Down

0 comments on commit dfec161

Please sign in to comment.