mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-17 00:21:19 +00:00
add httpUserAgent option, add customized user-agent support to C#
This commit is contained in:
@@ -84,6 +84,9 @@ namespace {{packageName}}.Client
|
||||
String contentType)
|
||||
{
|
||||
var request = new RestRequest(path, method);
|
||||
|
||||
// add user agent header
|
||||
request.AddHeader("User-Agent", Configuration.HttpUserAgent);
|
||||
|
||||
// add path parameter, if any
|
||||
foreach(var param in pathParams)
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace {{packageName}}.Client
|
||||
Dictionary<String, String> apiKeyPrefix = null,
|
||||
string tempFolderPath = null,
|
||||
string dateTimeFormat = null,
|
||||
int timeout = 100000
|
||||
int timeout = 100000,
|
||||
string httpUserAgent = "{{#httpUserAgent}}{{.}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{packageVersion}}/csharp{{/httpUserAgent}}"
|
||||
)
|
||||
{
|
||||
setApiClientUsingDefault(apiClient);
|
||||
@@ -42,6 +43,7 @@ namespace {{packageName}}.Client
|
||||
Username = username;
|
||||
Password = password;
|
||||
AccessToken = accessToken;
|
||||
HttpUserAgent = httpUserAgent;
|
||||
|
||||
if (defaultHeader != null)
|
||||
DefaultHeader = defaultHeader;
|
||||
@@ -146,6 +148,12 @@ namespace {{packageName}}.Client
|
||||
_defaultHeaderMap.Add(key, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP user agent.
|
||||
/// </summary>
|
||||
/// <value>Http user agent.</value>
|
||||
public String HttpUserAgent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the username (HTTP basic authentication).
|
||||
/// </summary>
|
||||
|
||||
@@ -82,6 +82,12 @@ namespace {{packageName}}.Api
|
||||
public {{classname}}(String basePath)
|
||||
{
|
||||
this.Configuration = new Configuration(new ApiClient(basePath));
|
||||
|
||||
// ensure API client has configuration ready
|
||||
if (Configuration.ApiClient.Configuration == null)
|
||||
{
|
||||
this.Configuration.ApiClient.Configuration = this.Configuration;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -96,6 +102,12 @@ namespace {{packageName}}.Api
|
||||
this.Configuration = Configuration.Default;
|
||||
else
|
||||
this.Configuration = configuration;
|
||||
|
||||
// ensure API client has configuration ready
|
||||
if (Configuration.ApiClient.Configuration == null)
|
||||
{
|
||||
this.Configuration.ApiClient.Configuration = this.Configuration;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user