diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
index 8a22c2f23f9b..049f8814fc37 100644
--- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
+++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache
@@ -265,7 +265,7 @@ namespace {{packageName}}.Client
var match = regex.Match(header.ToString());
if (match.Success)
{
- string fileName = filePath + match.Groups[1].Value.Replace("\"", "").Replace("'", "");
+ string fileName = filePath + SanitizeFilename(match.Groups[1].Value.Replace("\"", "").Replace("'", ""));
File.WriteAllBytes(fileName, data);
return new FileStream(fileName, FileMode.Open);
}
@@ -426,6 +426,23 @@ namespace {{packageName}}.Client
return sb.ToString();
}
-
+ ///
+ /// Sanitize filename by removing the path
+ ///
+ /// Filename
+ /// Filename
+ public static string SanitizeFilename(string filename)
+ {
+ Match match = Regex.Match(filename, @".*[/\\](.*)$");
+
+ if (match.Success)
+ {
+ return match.Groups[1].Value;
+ }
+ else
+ {
+ return filename;
+ }
+ }
}
}
diff --git a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache
index d3ef0c6f7316..029b38324c0c 100644
--- a/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache
+++ b/modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache
@@ -92,7 +92,8 @@ namespace {{packageName}}.Client
set
{
- ApiClient.RestClient.Timeout = value;
+ if (ApiClient != null)
+ ApiClient.RestClient.Timeout = value;
}
}
diff --git a/modules/swagger-codegen/src/main/resources/csharp/model.mustache b/modules/swagger-codegen/src/main/resources/csharp/model.mustache
index 6db39b046a26..96e17d8d1d3e 100644
--- a/modules/swagger-codegen/src/main/resources/csharp/model.mustache
+++ b/modules/swagger-codegen/src/main/resources/csharp/model.mustache
@@ -108,7 +108,7 @@ namespace {{packageName}}.Model
// Suitable nullity checks etc, of course :)
{{#vars}}
if (this.{{name}} != null)
- hash = hash * 57 + this.{{name}}.GetHashCode();
+ hash = hash * 59 + this.{{name}}.GetHashCode();
{{/vars}}
return hash;
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
index ab115aba9805..9ebd05fa7312 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/ApiClient.cs
@@ -265,7 +265,7 @@ namespace IO.Swagger.Client
var match = regex.Match(header.ToString());
if (match.Success)
{
- string fileName = filePath + match.Groups[1].Value.Replace("\"", "").Replace("'", "");
+ string fileName = filePath + SanitizeFilename(match.Groups[1].Value.Replace("\"", "").Replace("'", ""));
File.WriteAllBytes(fileName, data);
return new FileStream(fileName, FileMode.Open);
}
@@ -426,6 +426,23 @@ namespace IO.Swagger.Client
return sb.ToString();
}
-
+ ///
+ /// Sanitize filename by removing the path
+ ///
+ /// Filename
+ /// Filename
+ public static string SanitizeFilename(string filename)
+ {
+ Match match = Regex.Match(filename, @".*[/\\](.*)$");
+
+ if (match.Success)
+ {
+ return match.Groups[1].Value;
+ }
+ else
+ {
+ return filename;
+ }
+ }
}
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs
index 7ea30009c9ca..3df5d02c1160 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Client/Configuration.cs
@@ -92,7 +92,8 @@ namespace IO.Swagger.Client
set
{
- ApiClient.RestClient.Timeout = value;
+ if (ApiClient != null)
+ ApiClient.RestClient.Timeout = value;
}
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs
index 85694bc93c88..11223d889919 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Category.cs
@@ -112,10 +112,10 @@ namespace IO.Swagger.Model
// Suitable nullity checks etc, of course :)
if (this.Id != null)
- hash = hash * 57 + this.Id.GetHashCode();
+ hash = hash * 59 + this.Id.GetHashCode();
if (this.Name != null)
- hash = hash * 57 + this.Name.GetHashCode();
+ hash = hash * 59 + this.Name.GetHashCode();
return hash;
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs
index 5a110929b20e..c09efc1acf1a 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Order.cs
@@ -165,22 +165,22 @@ namespace IO.Swagger.Model
// Suitable nullity checks etc, of course :)
if (this.Id != null)
- hash = hash * 57 + this.Id.GetHashCode();
+ hash = hash * 59 + this.Id.GetHashCode();
if (this.PetId != null)
- hash = hash * 57 + this.PetId.GetHashCode();
+ hash = hash * 59 + this.PetId.GetHashCode();
if (this.Quantity != null)
- hash = hash * 57 + this.Quantity.GetHashCode();
+ hash = hash * 59 + this.Quantity.GetHashCode();
if (this.ShipDate != null)
- hash = hash * 57 + this.ShipDate.GetHashCode();
+ hash = hash * 59 + this.ShipDate.GetHashCode();
if (this.Status != null)
- hash = hash * 57 + this.Status.GetHashCode();
+ hash = hash * 59 + this.Status.GetHashCode();
if (this.Complete != null)
- hash = hash * 57 + this.Complete.GetHashCode();
+ hash = hash * 59 + this.Complete.GetHashCode();
return hash;
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs
index ec3b3d5ca13e..313103a3b8ab 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Pet.cs
@@ -165,22 +165,22 @@ namespace IO.Swagger.Model
// Suitable nullity checks etc, of course :)
if (this.Id != null)
- hash = hash * 57 + this.Id.GetHashCode();
+ hash = hash * 59 + this.Id.GetHashCode();
if (this.Category != null)
- hash = hash * 57 + this.Category.GetHashCode();
+ hash = hash * 59 + this.Category.GetHashCode();
if (this.Name != null)
- hash = hash * 57 + this.Name.GetHashCode();
+ hash = hash * 59 + this.Name.GetHashCode();
if (this.PhotoUrls != null)
- hash = hash * 57 + this.PhotoUrls.GetHashCode();
+ hash = hash * 59 + this.PhotoUrls.GetHashCode();
if (this.Tags != null)
- hash = hash * 57 + this.Tags.GetHashCode();
+ hash = hash * 59 + this.Tags.GetHashCode();
if (this.Status != null)
- hash = hash * 57 + this.Status.GetHashCode();
+ hash = hash * 59 + this.Status.GetHashCode();
return hash;
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs
index 078a53ad1ea2..2c1cb092a356 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/Tag.cs
@@ -112,10 +112,10 @@ namespace IO.Swagger.Model
// Suitable nullity checks etc, of course :)
if (this.Id != null)
- hash = hash * 57 + this.Id.GetHashCode();
+ hash = hash * 59 + this.Id.GetHashCode();
if (this.Name != null)
- hash = hash * 57 + this.Name.GetHashCode();
+ hash = hash * 59 + this.Name.GetHashCode();
return hash;
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs
index 7f0b3b858aa1..abbcea65b58a 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/Lib/SwaggerClient/src/main/csharp/IO/Swagger/Model/User.cs
@@ -191,28 +191,28 @@ namespace IO.Swagger.Model
// Suitable nullity checks etc, of course :)
if (this.Id != null)
- hash = hash * 57 + this.Id.GetHashCode();
+ hash = hash * 59 + this.Id.GetHashCode();
if (this.Username != null)
- hash = hash * 57 + this.Username.GetHashCode();
+ hash = hash * 59 + this.Username.GetHashCode();
if (this.FirstName != null)
- hash = hash * 57 + this.FirstName.GetHashCode();
+ hash = hash * 59 + this.FirstName.GetHashCode();
if (this.LastName != null)
- hash = hash * 57 + this.LastName.GetHashCode();
+ hash = hash * 59 + this.LastName.GetHashCode();
if (this.Email != null)
- hash = hash * 57 + this.Email.GetHashCode();
+ hash = hash * 59 + this.Email.GetHashCode();
if (this.Password != null)
- hash = hash * 57 + this.Password.GetHashCode();
+ hash = hash * 59 + this.Password.GetHashCode();
if (this.Phone != null)
- hash = hash * 57 + this.Phone.GetHashCode();
+ hash = hash * 59 + this.Phone.GetHashCode();
if (this.UserStatus != null)
- hash = hash * 57 + this.UserStatus.GetHashCode();
+ hash = hash * 59 + this.UserStatus.GetHashCode();
return hash;
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/TestApiClient.cs b/samples/client/petstore/csharp/SwaggerClientTest/TestApiClient.cs
index 6eb32a384427..d57627a623a5 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/TestApiClient.cs
+++ b/samples/client/petstore/csharp/SwaggerClientTest/TestApiClient.cs
@@ -95,6 +95,22 @@ namespace SwaggerClientTest.TestApiClient
DateTime dateUtc = DateTime.Parse("2009-06-15 20:45:30Z", null, System.Globalization.DateTimeStyles.RoundtripKind);
Assert.AreEqual("15/06/09 20:45:30", api.ParameterToString(dateUtc));
}
+
+ [Test ()]
+ public void TestSanitizeFilename ()
+ {
+ Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("sun.gif"));
+ Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("../sun.gif"));
+ Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("/var/tmp/sun.gif"));
+ Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("./sun.gif"));
+
+ Assert.AreEqual("sun", ApiClient.SanitizeFilename("sun"));
+ Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("..\\sun.gif"));
+ Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("\\var\\tmp\\sun.gif"));
+ Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename("c:\\var\\tmp\\sun.gif"));
+ Assert.AreEqual("sun.gif", ApiClient.SanitizeFilename(".\\sun.gif"));
+
+ }
}
}
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
index 807ef197edf8..f70fa971c5b1 100755
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll differ
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
index d4c01b5c42a8..d52933b2189b 100644
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb and b/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb differ
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt
index 285fc683bfc6..f115c595d6a0 100644
--- a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt
+++ b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.csproj.FilesWrittenAbsolute.txt
@@ -1,9 +1,9 @@
-/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
-/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png
-/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
-/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
-/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
-/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
-/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
-/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
-/Users/williamcheng/Code/tmp/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
+/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
+/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png
+/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
+/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
+/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
+/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
+/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
+/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
+/Users/williamcheng/Code/wing328/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
diff --git a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
index 807ef197edf8..f70fa971c5b1 100755
Binary files a/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll and b/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll differ