Skip to content

Commit

Permalink
Added UseGetBaseUrlMethod setting
Browse files Browse the repository at this point in the history
  • Loading branch information
RicoSuter committed Jul 12, 2017
1 parent 59920d9 commit 37bf33b
Show file tree
Hide file tree
Showing 14 changed files with 549 additions and 369 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public TypeScriptClientTemplateModel(
/// <summary>Gets a value indicating whether the client class has a base class.</summary>
public bool HasClientBaseClass => !string.IsNullOrEmpty(ClientBaseClass);

/// <summary>Gets or sets a value indicating whether to use the getBaseUrl(defaultUrl: string) from the base class.</summary>
public bool UseGetBaseUrlMethod => _settings.UseGetBaseUrlMethod;

/// <summary>Gets the configuration class name.</summary>
public string ConfigurationClass => _settings.ConfigurationClass;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public SwaggerToTypeScriptClientGeneratorSettings()
/// <summary>Gets or sets a value indicating whether required types should be imported (default: true).</summary>
public bool ImportRequiredTypes { get; set; } = true;

/// <summary>Gets or sets a value indicating whether to use the 'getBaseUrl(defaultUrl: string)' from the base class (default: false).</summary>
public bool UseGetBaseUrlMethod { get; set; }

internal ITemplate CreateTemplate(object model)
{
if (Template == TypeScriptTemplate.Aurelia)
Expand Down
174 changes: 101 additions & 73 deletions src/NSwag.CodeGeneration.TypeScript/Templates/AngularClientTemplate.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ export class <#=Model.Class#> <#if(Model.HasClientBaseClass){#>extends <#=Model.
super(<#if(Model.HasConfigurationClass){#>configuration<#}#>);
<#}#>
this.http = http;
<#if(Model.UseGetBaseUrlMethod){#>
this.baseUrl = baseUrl ? baseUrl : this.getBaseUrl("<#=Model.BaseUrl#>");
<#}else{#>
this.baseUrl = baseUrl ? baseUrl : "<#=Model.BaseUrl#>";
<#}#>
}
<#}#>
<#if(Model.HasExtensionCode){#>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export class <#=Model.Class#> <#if(Model.HasClientBaseClass){#>extends <#=Model.
<#}#>
this.http = $http;
this.q = $q;
<#if(Model.UseGetBaseUrlMethod){#>
this.baseUrl = baseUrl ? baseUrl : this.getBaseUrl("<#=Model.BaseUrl#>");
<#}else{#>
this.baseUrl = baseUrl ? baseUrl : "<#=Model.BaseUrl#>";
<#}#>
}
<#}#>
<#if(Model.HasExtensionCode){#>
Expand Down
162 changes: 98 additions & 64 deletions src/NSwag.CodeGeneration.TypeScript/Templates/FetchClientTemplate.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ export class <#=Model.Class#> <#if(Model.HasClientBaseClass){#>extends <#=Model.
<#if(Model.HasClientBaseClass){#>
super(<#if(Model.HasConfigurationClass){#>configuration<#}#>);
<#}#>
this.baseUrl = baseUrl ? baseUrl : "";
this.http = http ? http : <any>window;
<#if(Model.UseGetBaseUrlMethod){#>
this.baseUrl = baseUrl ? baseUrl : this.getBaseUrl("<#=Model.BaseUrl#>");
<#}else{#>
this.baseUrl = baseUrl ? baseUrl : "<#=Model.BaseUrl#>";
<#}#>
}
<#}#>
<#if(Model.HasExtensionCode){#>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export class <#=Model.Class#> <#if(Model.HasClientBaseClass){#>extends <#=Model.
<#if(Model.HasClientBaseClass){#>
super(<#if(Model.HasConfigurationClass){#>configuration<#}#>);
<#}#>
<#if(Model.UseGetBaseUrlMethod){#>
this.baseUrl = baseUrl ? baseUrl : this.getBaseUrl("<#=Model.BaseUrl#>");
<#}else{#>
this.baseUrl = baseUrl ? baseUrl : "<#=Model.BaseUrl#>";
<#}#>
}
<#}#>
<#if(Model.HasExtensionCode){#>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export class <#=Model.Class#> <#if(Model.HasClientBaseClass){#>extends <#=Model.
<#if(Model.HasClientBaseClass){#>
super(<#if(Model.HasConfigurationClass){#>configuration<#}#>);
<#}#>
this.baseUrl = baseUrl ? baseUrl : "<#=Model.BaseUrl#>";
<#if(Model.UseGetBaseUrlMethod){#>
this.baseUrl = baseUrl ? baseUrl : this.getBaseUrl("<#=Model.BaseUrl#>");
<#}else{#>
this.baseUrl = baseUrl ? baseUrl : "<#=Model.BaseUrl#>";
<#}#>
}
<#}#>
<#if(Model.HasExtensionCode){#>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ public bool ImportRequiredTypes
set { Settings.ImportRequiredTypes = value; }
}

[Argument(Name = "UseGetBaseUrlMethod", IsRequired = false, Description = "Specifies whether to use the 'getBaseUrl(defaultUrl: string)' method from the base class (default: false).")]
public bool UseGetBaseUrlMethod
{
get { return Settings.UseGetBaseUrlMethod; }
set { Settings.UseGetBaseUrlMethod = value; }
}

[Argument(Name = "BaseUrlTokenName", IsRequired = false, Description = "The token name for injecting the API base URL string (used in the Angular template, default: 'API_BASE_URL').")]
public string BaseUrlTokenName
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
<TextBlock Text="Configuration Class Name (passed to base class ctor, optional)" FontWeight="Bold" Margin="0,0,0,6" />
<TextBox Text="{Binding Command.ConfigurationClass, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Margin="0,0,0,12" ToolTip="ConfigurationClass" />

<CheckBox IsChecked="{Binding Command.UseGetBaseUrlMethod, Mode=TwoWay}"
ToolTip="UseGetBaseUrlMethod"
Content="Use the 'getBaseUrl(defaultUrl: string)' method from the base class" Margin="0,0,0,12" />
</StackPanel>

<CheckBox IsChecked="{Binding Command.GenerateClientInterfaces, Mode=TwoWay}"
Expand Down

0 comments on commit 37bf33b

Please sign in to comment.