mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-06 15:40:54 +00:00
Merge pull request #2240 from wing328/csharp_better_reserved_word
[C#] add better reserved keyword handling for c#
This commit is contained in:
commit
005584cf2a
@ -276,14 +276,15 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
@Override
|
||||
public String toOperationId(String operationId) {
|
||||
// throw exception if method name is empty
|
||||
// throw exception if method name is empty (should not occur as an auto-generated method name will be used)
|
||||
if (StringUtils.isEmpty(operationId)) {
|
||||
throw new RuntimeException("Empty method name (operationId) not allowed");
|
||||
}
|
||||
|
||||
// method name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(operationId)) {
|
||||
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
|
||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId)));
|
||||
operationId = "call_" + operationId;
|
||||
}
|
||||
|
||||
return camelize(sanitizeName(operationId));
|
||||
@ -471,7 +472,8 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
|
||||
|
||||
// model name cannot use reserved keyword, e.g. return
|
||||
if (reservedWords.contains(name)) {
|
||||
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
|
||||
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
|
||||
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
|
||||
}
|
||||
|
||||
// camelize the model name
|
||||
|
@ -156,15 +156,15 @@ namespace IO.Swagger.Test
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test GetPetByIdWithByteArray
|
||||
/// Test PetPetIdtestingByteArraytrueGet
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void GetPetByIdWithByteArrayTest()
|
||||
public void PetPetIdtestingByteArraytrueGetTest()
|
||||
{
|
||||
// TODO: add unit test for the method 'GetPetByIdWithByteArray'
|
||||
// TODO: add unit test for the method 'PetPetIdtestingByteArraytrueGet'
|
||||
long? petId = null; // TODO: replace null with proper value
|
||||
|
||||
var response = instance.GetPetByIdWithByteArray(petId);
|
||||
var response = instance.PetPetIdtestingByteArraytrueGet(petId);
|
||||
Assert.IsInstanceOf<byte[]> (response, "response is byte[]");
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ namespace IO.Swagger.Api
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="petId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>byte[]</returns>
|
||||
byte[] GetPetByIdWithByteArray (long? petId);
|
||||
byte[] PetPetIdtestingByteArraytrueGet (long? petId);
|
||||
|
||||
/// <summary>
|
||||
/// Fake endpoint to test byte array return by 'Find pet by ID'
|
||||
@ -223,7 +223,7 @@ namespace IO.Swagger.Api
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="petId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>ApiResponse of byte[]</returns>
|
||||
ApiResponse<byte[]> GetPetByIdWithByteArrayWithHttpInfo (long? petId);
|
||||
ApiResponse<byte[]> PetPetIdtestingByteArraytrueGetWithHttpInfo (long? petId);
|
||||
|
||||
/// <summary>
|
||||
/// Fake endpoint to test byte array in body parameter for adding a new pet to the store
|
||||
@ -446,7 +446,7 @@ namespace IO.Swagger.Api
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="petId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Task of byte[]</returns>
|
||||
System.Threading.Tasks.Task<byte[]> GetPetByIdWithByteArrayAsync (long? petId);
|
||||
System.Threading.Tasks.Task<byte[]> PetPetIdtestingByteArraytrueGetAsync (long? petId);
|
||||
|
||||
/// <summary>
|
||||
/// Fake endpoint to test byte array return by 'Find pet by ID'
|
||||
@ -457,7 +457,7 @@ namespace IO.Swagger.Api
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="petId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Task of ApiResponse (byte[])</returns>
|
||||
System.Threading.Tasks.Task<ApiResponse<byte[]>> GetPetByIdWithByteArrayAsyncWithHttpInfo (long? petId);
|
||||
System.Threading.Tasks.Task<ApiResponse<byte[]>> PetPetIdtestingByteArraytrueGetAsyncWithHttpInfo (long? petId);
|
||||
|
||||
/// <summary>
|
||||
/// Fake endpoint to test byte array in body parameter for adding a new pet to the store
|
||||
@ -1972,9 +1972,9 @@ namespace IO.Swagger.Api
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="petId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>byte[]</returns>
|
||||
public byte[] GetPetByIdWithByteArray (long? petId)
|
||||
public byte[] PetPetIdtestingByteArraytrueGet (long? petId)
|
||||
{
|
||||
ApiResponse<byte[]> response = GetPetByIdWithByteArrayWithHttpInfo(petId);
|
||||
ApiResponse<byte[]> response = PetPetIdtestingByteArraytrueGetWithHttpInfo(petId);
|
||||
return response.Data;
|
||||
}
|
||||
|
||||
@ -1984,12 +1984,12 @@ namespace IO.Swagger.Api
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="petId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>ApiResponse of byte[]</returns>
|
||||
public ApiResponse< byte[] > GetPetByIdWithByteArrayWithHttpInfo (long? petId)
|
||||
public ApiResponse< byte[] > PetPetIdtestingByteArraytrueGetWithHttpInfo (long? petId)
|
||||
{
|
||||
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null)
|
||||
throw new ApiException(400, "Missing required parameter 'petId' when calling PetApi->GetPetByIdWithByteArray");
|
||||
throw new ApiException(400, "Missing required parameter 'petId' when calling PetApi->PetPetIdtestingByteArraytrueGet");
|
||||
|
||||
|
||||
var path_ = "/pet/{petId}?testing_byte_array=true";
|
||||
@ -2048,9 +2048,9 @@ namespace IO.Swagger.Api
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling GetPetByIdWithByteArray: " + response.Content, response.Content);
|
||||
throw new ApiException (statusCode, "Error calling PetPetIdtestingByteArraytrueGet: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling GetPetByIdWithByteArray: " + response.ErrorMessage, response.ErrorMessage);
|
||||
throw new ApiException (statusCode, "Error calling PetPetIdtestingByteArraytrueGet: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return new ApiResponse<byte[]>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
@ -2065,9 +2065,9 @@ namespace IO.Swagger.Api
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="petId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Task of byte[]</returns>
|
||||
public async System.Threading.Tasks.Task<byte[]> GetPetByIdWithByteArrayAsync (long? petId)
|
||||
public async System.Threading.Tasks.Task<byte[]> PetPetIdtestingByteArraytrueGetAsync (long? petId)
|
||||
{
|
||||
ApiResponse<byte[]> response = await GetPetByIdWithByteArrayAsyncWithHttpInfo(petId);
|
||||
ApiResponse<byte[]> response = await PetPetIdtestingByteArraytrueGetAsyncWithHttpInfo(petId);
|
||||
return response.Data;
|
||||
|
||||
}
|
||||
@ -2078,10 +2078,10 @@ namespace IO.Swagger.Api
|
||||
/// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
|
||||
/// <param name="petId">ID of pet that needs to be fetched</param>
|
||||
/// <returns>Task of ApiResponse (byte[])</returns>
|
||||
public async System.Threading.Tasks.Task<ApiResponse<byte[]>> GetPetByIdWithByteArrayAsyncWithHttpInfo (long? petId)
|
||||
public async System.Threading.Tasks.Task<ApiResponse<byte[]>> PetPetIdtestingByteArraytrueGetAsyncWithHttpInfo (long? petId)
|
||||
{
|
||||
// verify the required parameter 'petId' is set
|
||||
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling GetPetByIdWithByteArray");
|
||||
if (petId == null) throw new ApiException(400, "Missing required parameter 'petId' when calling PetPetIdtestingByteArraytrueGet");
|
||||
|
||||
|
||||
var path_ = "/pet/{petId}?testing_byte_array=true";
|
||||
@ -2142,9 +2142,9 @@ namespace IO.Swagger.Api
|
||||
int statusCode = (int) response.StatusCode;
|
||||
|
||||
if (statusCode >= 400)
|
||||
throw new ApiException (statusCode, "Error calling GetPetByIdWithByteArray: " + response.Content, response.Content);
|
||||
throw new ApiException (statusCode, "Error calling PetPetIdtestingByteArraytrueGet: " + response.Content, response.Content);
|
||||
else if (statusCode == 0)
|
||||
throw new ApiException (statusCode, "Error calling GetPetByIdWithByteArray: " + response.ErrorMessage, response.ErrorMessage);
|
||||
throw new ApiException (statusCode, "Error calling PetPetIdtestingByteArraytrueGet: " + response.ErrorMessage, response.ErrorMessage);
|
||||
|
||||
return new ApiResponse<byte[]>(statusCode,
|
||||
response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
|
||||
|
@ -1,8 +1,8 @@
|
||||
<Properties StartupItem="SwaggerClientTest.csproj">
|
||||
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" />
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="TestOrder.cs">
|
||||
<MonoDevelop.Ide.Workbench ActiveDocument="TestPet.cs">
|
||||
<Files>
|
||||
<File FileName="TestPet.cs" Line="84" Column="10" />
|
||||
<File FileName="TestPet.cs" Line="162" Column="35" />
|
||||
<File FileName="TestOrder.cs" Line="42" Column="12" />
|
||||
</Files>
|
||||
</MonoDevelop.Ide.Workbench>
|
||||
|
@ -168,7 +168,7 @@ namespace SwaggerClientTest.TestPet
|
||||
Configuration c1 = new Configuration (timeout: 10000);
|
||||
|
||||
PetApi petApi = new PetApi (c1);
|
||||
byte[] response = petApi.GetPetByIdWithByteArray (petId);
|
||||
byte[] response = petApi.PetPetIdtestingByteArraytrueGet (petId);
|
||||
Assert.IsInstanceOf<byte[]> (response, "Response is byte array");
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
/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
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/.NETFramework,Version=v4.5.AssemblyAttribute.cs
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.swagger-logo.png
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/obj/Debug/SwaggerClientTest.dll.mdb
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/Newtonsoft.Json.dll
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/nunit.framework.dll
|
||||
/Users/williamcheng/Code/swagger-codegen/samples/client/petstore/csharp/SwaggerClientTest/bin/Debug/RestSharp.dll
|
||||
|
Loading…
x
Reference in New Issue
Block a user