Skip to content

Commit f033f59

Browse files
committed
update reserved word list for C# .net 2.0 with local variable name in
api method
1 parent eeaf832 commit f033f59

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/CsharpDotNet2ClientCodegen.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ public CsharpDotNet2ClientCodegen() {
3333

3434
reservedWords = new HashSet<String>(
3535
Arrays.asList(
36-
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while")
36+
// local variable names in API methods (endpoints)
37+
"path", "queryParams", "headerParams", "formParams", "fileParams", "postBody",
38+
"authSettings", "response", "StatusCode",
39+
// C# reserved word
40+
"abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char", "checked", "class", "const", "continue", "decimal", "default", "delegate", "do", "double", "else", "enum", "event", "explicit", "extern", "false", "finally", "fixed", "float", "for", "foreach", "goto", "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed", "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this", "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort", "using", "virtual", "void", "volatile", "while")
3741
);
3842

3943

samples/client/petstore/csharp-dotnet2/SwaggerClientTest/Lib/SwaggerClient/src/main/CsharpDotNet2/IO/Swagger/Api/PetApi.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public Pet GetPetById (long? petId)
317317

318318

319319
// authentication setting, if any
320-
String[] authSettings = new String[] { "api_key", "petstore_auth" };
320+
String[] authSettings = new String[] { "api_key" };
321321

322322
// make the HTTP request
323323
IRestResponse response = (IRestResponse) ApiClient.CallApi(path, Method.GET, queryParams, postBody, headerParams, formParams, fileParams, authSettings);

samples/client/petstore/csharp-dotnet2/SwaggerClientTest/Lib/SwaggerClient/src/main/CsharpDotNet2/IO/Swagger/Api/UserApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public interface IUserApi
4949
/// <summary>
5050
/// Get user by user name
5151
/// </summary>
52-
/// <param name="username">The name that needs to be fetched. Use user1 for testing. </param>
52+
/// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
5353
/// <returns>User</returns>
5454
User GetUserByName (string username);
5555

@@ -327,7 +327,7 @@ public void LogoutUser ()
327327
/// <summary>
328328
/// Get user by user name
329329
/// </summary>
330-
/// <param name="username">The name that needs to be fetched. Use user1 for testing. </param>
330+
/// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
331331
/// <returns>User</returns>
332332
public User GetUserByName (string username)
333333
{

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public FileParameter ParameterToFile(string name, Stream stream)
134134
}
135135

136136
/// <summary>
137-
/// If parameter is DateTime, output in ISO8601 format.
137+
/// If parameter is DateTime, output in a formatted string (default ISO 8601), customizable with Configuration.DateTime.
138138
/// If parameter is a list of string, join the list with ",".
139139
/// Otherwise just return the string.
140140
/// </summary>
@@ -143,7 +143,11 @@ public FileParameter ParameterToFile(string name, Stream stream)
143143
public string ParameterToString(object obj)
144144
{
145145
if (obj is DateTime)
146-
return ((DateTime)obj).ToString ("u");
146+
// Return a formatted date string - Can be customized with Configuration.DateTimeFormat
147+
// Defaults to an ISO 8601, using the known as a Round-trip date/time pattern ("o")
148+
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
149+
// For example: 2009-06-15T13:45:30.0000000
150+
return ((DateTime)obj).ToString (Configuration.DateTimeFormat);
147151
else if (obj is List<string>)
148152
return String.Join(",", (obj as List<string>).ToArray());
149153
else

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,40 @@ public static String TempFolderPath
7878
_tempFolderPath = value + Path.DirectorySeparatorChar;
7979
}
8080
}
81-
81+
82+
private const string ISO8601_DATETIME_FORMAT = "o";
83+
84+
private static string _dateTimeFormat = ISO8601_DATETIME_FORMAT;
85+
86+
/// <summary>
87+
/// Gets or sets the the date time format used when serializing in the ApiClient
88+
/// By default, it's set to ISO 8601 - "o", for others see:
89+
/// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx
90+
/// and https://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx
91+
/// No validation is done to ensure that the string you're providing is valid
92+
/// </summary>
93+
/// <value>The DateTimeFormat string</value>
94+
public static String DateTimeFormat
95+
{
96+
get
97+
{
98+
return _dateTimeFormat;
99+
}
100+
set
101+
{
102+
if (string.IsNullOrEmpty(value))
103+
{
104+
// Never allow a blank or null string, go back to the default
105+
_dateTimeFormat = ISO8601_DATETIME_FORMAT;
106+
return;
107+
}
108+
109+
// Caution, no validation when you choose date time format other than ISO 8601
110+
// Take a look at the above links
111+
_dateTimeFormat = value;
112+
}
113+
}
114+
82115
/// <summary>
83116
/// Returns a string with essential information for debugging.
84117
/// </summary>

0 commit comments

Comments
 (0)