Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a6cd10d

Browse files
committed
fix http user agent in C#
1 parent 77777c7 commit a6cd10d

File tree

7 files changed

+38
-24
lines changed

7 files changed

+38
-24
lines changed

‎modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ namespace {{packageName}}.Client
8585
{
8686
var request = new RestRequest(path, method);
8787
88-
// add user agent header
89-
request.AddHeader("User-Agent", Configuration.HttpUserAgent);
90-
9188
// add path parameter, if any
9289
foreach(var param in pathParams)
9390
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
@@ -146,6 +143,11 @@ namespace {{packageName}}.Client
146143
path, method, queryParams, postBody, headerParams, formParams, fileParams,
147144
pathParams, contentType);
148145
146+
// set timeout
147+
RestClient.Timeout = Configuration.Timeout;
148+
// set user agent
149+
RestClient.UserAgent = Configuration.UserAgent;
150+
149151
var response = RestClient.Execute(request);
150152
return (Object) response;
151153
}

‎modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ namespace {{packageName}}.Client
3535
string tempFolderPath = null,
3636
string dateTimeFormat = null,
3737
int timeout = 100000,
38-
string httpUserAgent = "{{#httpUserAgent}}{{.}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{packageVersion}}/csharp{{/httpUserAgent}}"
38+
string userAgent = "{{#httpUserAgent}}{{.}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{packageVersion}}/csharp{{/httpUserAgent}}"
3939
)
4040
{
4141
setApiClientUsingDefault(apiClient);
4242
4343
Username = username;
4444
Password = password;
4545
AccessToken = accessToken;
46-
HttpUserAgent = httpUserAgent;
46+
UserAgent = userAgent;
4747
4848
if (defaultHeader != null)
4949
DefaultHeader = defaultHeader;
@@ -152,7 +152,7 @@ namespace {{packageName}}.Client
152152
/// Gets or sets the HTTP user agent.
153153
/// </summary>
154154
/// <value>Http user agent.</value>
155-
public String HttpUserAgent { get; set; }
155+
public String UserAgent { get; set; }
156156

157157
/// <summary>
158158
/// Gets or sets the username (HTTP basic authentication).

‎samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ private RestRequest PrepareRequest(
8585
{
8686
var request = new RestRequest(path, method);
8787

88-
// add user agent header
89-
request.AddHeader("User-Agent", Configuration.HttpUserAgent);
90-
9188
// add path parameter, if any
9289
foreach(var param in pathParams)
9390
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
@@ -146,6 +143,11 @@ public Object CallApi(
146143
path, method, queryParams, postBody, headerParams, formParams, fileParams,
147144
pathParams, contentType);
148145

146+
// set timeout
147+
RestClient.Timeout = Configuration.Timeout;
148+
// set user agent
149+
RestClient.UserAgent = Configuration.UserAgent;
150+
149151
var response = RestClient.Execute(request);
150152
return (Object) response;
151153
}

‎samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public Configuration(ApiClient apiClient = null,
3535
string tempFolderPath = null,
3636
string dateTimeFormat = null,
3737
int timeout = 100000,
38-
string httpUserAgent = "Swagger-Codegen/1.0.0/csharp"
38+
string userAgent = "Swagger-Codegen/1.0.0/csharp"
3939
)
4040
{
4141
setApiClientUsingDefault(apiClient);
4242

4343
Username = username;
4444
Password = password;
4545
AccessToken = accessToken;
46-
HttpUserAgent = httpUserAgent;
46+
UserAgent = userAgent;
4747

4848
if (defaultHeader != null)
4949
DefaultHeader = defaultHeader;
@@ -152,7 +152,7 @@ public void AddDefaultHeader(string key, string value)
152152
/// Gets or sets the HTTP user agent.
153153
/// </summary>
154154
/// <value>Http user agent.</value>
155-
public String HttpUserAgent { get; set; }
155+
public String UserAgent { get; set; }
156156

157157
/// <summary>
158158
/// Gets or sets the username (HTTP basic authentication).

‎samples/client/petstore/csharp/SwaggerClientTest/SwaggerClientTest.userprefs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
33
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
44
<Files>
5-
<File FileName="TestPet.cs" Line="69" Column="32" />
5+
<File FileName="TestPet.cs" Line="139" Column="26" />
66
<File FileName="TestOrder.cs" Line="1" Column="1" />
77
</Files>
88
<Pads>
99
<Pad Id="MonoDevelop.NUnit.TestPad">
1010
<State name="__root__">
11-
<Node name="SwaggerClientTest" expanded="True" />
11+
<Node name="SwaggerClientTest" expanded="True">
12+
<Node name="SwaggerClientTest" expanded="True">
13+
<Node name="SwaggerClientTest" expanded="True">
14+
<Node name="TestPet" expanded="True">
15+
<Node name="TestPet" expanded="True">
16+
<Node name="TestGetPetById" selected="True" />
17+
</Node>
18+
</Node>
19+
</Node>
20+
</Node>
21+
</Node>
1222
</State>
1323
</Pad>
1424
</Pads>

‎samples/client/petstore/csharp/SwaggerClientTest/TestPet.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void TestGetPetByIdAsyncWithHttpInfo ()
136136
public void TestGetPetById ()
137137
{
138138
// set timeout to 10 seconds
139-
Configuration c1 = new Configuration (timeout: 10000);
139+
Configuration c1 = new Configuration (timeout: 10000,userAgent:"TEST_USER_AGENT");
140140

141141
PetApi petApi = new PetApi (c1);
142142
Pet response = petApi.GetPetById (petId);
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
2-
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png
3-
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
4-
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
5-
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
6-
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
7-
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
8-
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
9-
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
1+
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
2+
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png
3+
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
4+
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
5+
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
6+
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
7+
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
8+
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
9+
/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /