From 2c0e8f6079256fed9a5f2e51bf5733e016bdd25b Mon Sep 17 00:00:00 2001 From: William Cheng Date: Tue, 21 Apr 2015 22:42:13 +0800 Subject: [PATCH] fix csharp model name issue --- .../codegen/languages/CSharpClientCodegen.java | 14 ++++++++++++-- .../src/main/csharp/io/swagger/Api/PetApi.cs | 18 +++++++++--------- .../src/main/csharp/io/swagger/Api/StoreApi.cs | 4 ++-- .../src/main/csharp/io/swagger/Api/UserApi.cs | 14 +++++++------- .../main/csharp/io/swagger/Model/Category.cs | 2 +- .../src/main/csharp/io/swagger/Model/Order.cs | 2 +- .../src/main/csharp/io/swagger/Model/Pet.cs | 6 +++--- .../src/main/csharp/io/swagger/Model/Tag.cs | 2 +- .../src/main/csharp/io/swagger/Model/User.cs | 12 ++++++------ 9 files changed, 42 insertions(+), 32 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/CSharpClientCodegen.java b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/CSharpClientCodegen.java index d815ade09151..8203a83b3491 100644 --- a/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/CSharpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/com/wordnik/swagger/codegen/languages/CSharpClientCodegen.java @@ -50,8 +50,17 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig languageSpecificPrimitives = new HashSet( Arrays.asList( + "string?", + "bool?", + "double?", + "int?", + "long?", + "float?", + "byte[]", + "List", + "Dictionary", + "DateTime", "String", - "boolean", "Boolean", "Double", "Integer", @@ -63,6 +72,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig instantiationTypes.put("map", "Dictionary"); typeMapping = new HashMap(); + typeMapping.put("string", "string?"); typeMapping.put("boolean", "bool?"); typeMapping.put("integer", "int?"); typeMapping.put("float", "float?"); @@ -161,7 +171,7 @@ public class CSharpClientCodegen extends DefaultCodegen implements CodegenConfig } else type = swaggerType; - return type; + return toModelName(type); } @Override diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/PetApi.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/PetApi.cs index 4f20c0cba455..6bbaa142c4a0 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/PetApi.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/PetApi.cs @@ -132,7 +132,7 @@ namespace io.swagger.Api { /// Status values that need to be considered for filter /// - public List FindPetsByStatus (List Status) { + public List FindPetsByStatus (List Status) { // create path and map variables var path = "/pet/findByStatus".Replace("{format}","json"); @@ -188,7 +188,7 @@ namespace io.swagger.Api { /// Tags to filter by /// - public List FindPetsByTags (List Tags) { + public List FindPetsByTags (List Tags) { // create path and map variables var path = "/pet/findByTags".Replace("{format}","json"); @@ -244,7 +244,7 @@ namespace io.swagger.Api { /// ID of pet that needs to be fetched /// - public Pet GetPetById (long? PetId) { + public PetTest GetPetById (long? PetId) { // create path and map variables var path = "/pet/{petId}".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId)); @@ -262,17 +262,17 @@ namespace io.swagger.Api { try { - if (typeof(Pet) == typeof(byte[])) { + if (typeof(PetTest) == typeof(byte[])) { var response = apiInvoker.invokeBinaryAPI(basePath, path, "GET", queryParams, null, headerParams, formParams); - return ((object)response) as Pet; + return ((object)response) as PetTest; } else { var response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams); if (response != null){ - return (Pet) ApiInvoker.deserialize(response, typeof(Pet)); + return (PetTest) ApiInvoker.deserialize(response, typeof(PetTest)); } else { return null; @@ -299,7 +299,7 @@ namespace io.swagger.Api { /// Updated status of the pet /// - public void UpdatePetWithForm (string PetId, string Name, string Status) { + public void UpdatePetWithForm (string? PetId, string? Name, string? Status) { // create path and map variables var path = "/pet/{petId}".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId)); @@ -362,7 +362,7 @@ namespace io.swagger.Api { /// Pet id to delete /// - public void DeletePet (string ApiKey, long? PetId) { + public void DeletePet (string? ApiKey, long? PetId) { // create path and map variables var path = "/pet/{petId}".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId)); @@ -413,7 +413,7 @@ namespace io.swagger.Api { /// file to upload /// - public void UploadFile (long? PetId, string AdditionalMetadata, byte[] File) { + public void UploadFile (long? PetId, string? AdditionalMetadata, byte[] File) { // create path and map variables var path = "/pet/{petId}/uploadImage".Replace("{format}","json").Replace("{" + "petId" + "}", apiInvoker.ParameterToString(PetId)); diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/StoreApi.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/StoreApi.cs index 2514539e2984..e433ced7bc72 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/StoreApi.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/StoreApi.cs @@ -141,7 +141,7 @@ namespace io.swagger.Api { /// ID of pet that needs to be fetched /// - public Order GetOrderById (string OrderId) { + public Order GetOrderById (string? OrderId) { // create path and map variables var path = "/store/order/{orderId}".Replace("{format}","json").Replace("{" + "orderId" + "}", apiInvoker.ParameterToString(OrderId)); @@ -194,7 +194,7 @@ namespace io.swagger.Api { /// ID of the order that needs to be deleted /// - public void DeleteOrder (string OrderId) { + public void DeleteOrder (string? OrderId) { // create path and map variables var path = "/store/order/{orderId}".Replace("{format}","json").Replace("{" + "orderId" + "}", apiInvoker.ParameterToString(OrderId)); diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/UserApi.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/UserApi.cs index 4f1f4a1bf197..d706c029aab4 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/UserApi.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Api/UserApi.cs @@ -181,7 +181,7 @@ namespace io.swagger.Api { /// The password for login in clear text /// - public string LoginUser (string Username, string Password) { + public string? LoginUser (string? Username, string? Password) { // create path and map variables var path = "/user/login".Replace("{format}","json"); @@ -205,17 +205,17 @@ namespace io.swagger.Api { try { - if (typeof(string) == typeof(byte[])) { + if (typeof(string?) == typeof(byte[])) { var response = apiInvoker.invokeBinaryAPI(basePath, path, "GET", queryParams, null, headerParams, formParams); - return ((object)response) as string; + return ((object)response) as string?; } else { var response = apiInvoker.invokeAPI(basePath, path, "GET", queryParams, null, headerParams, formParams); if (response != null){ - return (string) ApiInvoker.deserialize(response, typeof(string)); + return (string?) ApiInvoker.deserialize(response, typeof(string?)); } else { return null; @@ -287,7 +287,7 @@ namespace io.swagger.Api { /// The name that needs to be fetched. Use user1 for testing. /// - public User GetUserByName (string Username) { + public User GetUserByName (string? Username) { // create path and map variables var path = "/user/{username}".Replace("{format}","json").Replace("{" + "username" + "}", apiInvoker.ParameterToString(Username)); @@ -341,7 +341,7 @@ namespace io.swagger.Api { /// Updated user object /// - public void UpdateUser (string Username, User Body) { + public void UpdateUser (string? Username, User Body) { // create path and map variables var path = "/user/{username}".Replace("{format}","json").Replace("{" + "username" + "}", apiInvoker.ParameterToString(Username)); @@ -389,7 +389,7 @@ namespace io.swagger.Api { /// The name that needs to be deleted /// - public void DeleteUser (string Username) { + public void DeleteUser (string? Username) { // create path and map variables var path = "/user/{username}".Replace("{format}","json").Replace("{" + "username" + "}", apiInvoker.ParameterToString(Username)); diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Category.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Category.cs index bfe1c0c4be82..57a3c740b7ef 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Category.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Category.cs @@ -13,7 +13,7 @@ namespace io.swagger.Model { - public string Name { get; set; } + public string? Name { get; set; } diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Order.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Order.cs index 20a6d7367ddc..70976be64b31 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Order.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Order.cs @@ -29,7 +29,7 @@ namespace io.swagger.Model { /* Order Status */ - public string Status { get; set; } + public string? Status { get; set; } diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Pet.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Pet.cs index b0f3573b78c3..437368390f02 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Pet.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Pet.cs @@ -18,12 +18,12 @@ namespace io.swagger.Model { - public string Name { get; set; } + public string? Name { get; set; } - public List PhotoUrls { get; set; } + public List PhotoUrls { get; set; } @@ -34,7 +34,7 @@ namespace io.swagger.Model { /* pet status in the store */ - public string Status { get; set; } + public string? Status { get; set; } diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Tag.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Tag.cs index 2fbf70700504..cc4f7df25ffe 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Tag.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/Tag.cs @@ -13,7 +13,7 @@ namespace io.swagger.Model { - public string Name { get; set; } + public string? Name { get; set; } diff --git a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/User.cs b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/User.cs index 146ba13c7683..23f9e246c304 100644 --- a/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/User.cs +++ b/samples/client/petstore/csharp/src/main/csharp/io/swagger/Model/User.cs @@ -13,32 +13,32 @@ namespace io.swagger.Model { - public string Username { get; set; } + public string? Username { get; set; } - public string FirstName { get; set; } + public string? FirstName { get; set; } - public string LastName { get; set; } + public string? LastName { get; set; } - public string Email { get; set; } + public string? Email { get; set; } - public string Password { get; set; } + public string? Password { get; set; } - public string Phone { get; set; } + public string? Phone { get; set; }