From 5a257a055817dfaf4e2054d3950da2533f11afe2 Mon Sep 17 00:00:00 2001 From: Voydz Date: Wed, 10 May 2017 09:24:43 +0200 Subject: [PATCH] [csharp] fixes for netstandard (json serializing and project files) (#5590) --- .../src/main/resources/csharp/ApiClient.mustache | 14 ++++++++++++++ .../src/main/resources/csharp/Project.mustache | 5 ++++- .../SwaggerClient/src/IO.Swagger/Api/FakeApi.cs | 6 ++---- .../SwaggerClient/src/IO.Swagger/IO.Swagger.csproj | 5 ++++- .../src/IO.Swagger/Model/ModelReturn.cs | 2 +- .../SwaggerClient/src/IO.Swagger/IO.Swagger.csproj | 5 ++++- .../src/IO.Swagger/Client/ApiClient.cs | 6 ++++-- .../src/IO.Swagger/IO.Swagger.csproj | 5 ++++- .../src/IO.Swagger/IO.Swagger.csproj | 5 ++++- 9 files changed, 41 insertions(+), 12 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache index e51cee02c58..536e660a94d 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache @@ -122,6 +122,10 @@ namespace {{packageName}}.Client String contentType) { var request = new RestRequest(path, method); + {{#netStandard}} + // disable ResetSharp.Portable built-in serialization + request.Serializer = null; + {{/netStandard}} // add path parameter, if any foreach(var param in pathParams) @@ -161,11 +165,21 @@ namespace {{packageName}}.Client { if (postBody.GetType() == typeof(String)) { + {{#netStandard}} + request.AddParameter(new Parameter { Value = postBody, Type = ParameterType.RequestBody, ContentType = "application/json" }); + {{/netStandard}} + {{^netStandard}} request.AddParameter("application/json", postBody, ParameterType.RequestBody); + {{/netStandard}} } else if (postBody.GetType() == typeof(byte[])) { + {{#netStandard}} + request.AddParameter(new Parameter { Value = postBody, Type = ParameterType.RequestBody, ContentType = contentType }); + {{/netStandard}} + {{^netStandard}} request.AddParameter(contentType, postBody, ParameterType.RequestBody); + {{/netStandard}} } } diff --git a/modules/swagger-codegen/src/main/resources/csharp/Project.mustache b/modules/swagger-codegen/src/main/resources/csharp/Project.mustache index f238b8059e1..1f3749d5af2 100644 --- a/modules/swagger-codegen/src/main/resources/csharp/Project.mustache +++ b/modules/swagger-codegen/src/main/resources/csharp/Project.mustache @@ -88,7 +88,10 @@ {{/netStandard}} - + + + + {{^netStandard}} diff --git a/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs b/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs index e9ded41c0a5..63555667e9a 100644 --- a/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs +++ b/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Api/FakeApi.cs @@ -216,7 +216,7 @@ namespace IO.Swagger.Api // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { - "application/json", + "application/json", "*_/ ' =end - - " }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); @@ -239,7 +239,6 @@ namespace IO.Swagger.Api if (exception != null) throw exception; } - return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), null); @@ -283,7 +282,7 @@ namespace IO.Swagger.Api // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { - "application/json", + "application/json", "*_/ ' =end - - " }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); @@ -306,7 +305,6 @@ namespace IO.Swagger.Api if (exception != null) throw exception; } - return new ApiResponse(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), null); diff --git a/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj b/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj index c5f0a9ec4ea..191ac9a560e 100644 --- a/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj @@ -62,7 +62,10 @@ Contact: apiteam@swagger.io *_/ ' \" =end - - \\r\\n \\n \\r - + + + + diff --git a/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Model/ModelReturn.cs b/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Model/ModelReturn.cs index ebb142f3847..e75bd5c3156 100644 --- a/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Model/ModelReturn.cs +++ b/samples/client/petstore-security-test/csharp/SwaggerClient/src/IO.Swagger/Model/ModelReturn.cs @@ -119,7 +119,7 @@ namespace IO.Swagger.Model /// Validation context /// Validation Result IEnumerable IValidatableObject.Validate(ValidationContext validationContext) - { + { yield break; } } diff --git a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj index 6f55d545b7a..df95d7cfb58 100644 --- a/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/client/petstore/csharp/SwaggerClient/src/IO.Swagger/IO.Swagger.csproj @@ -62,7 +62,10 @@ Contact: apiteam@swagger.io - + + + + diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Client/ApiClient.cs b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Client/ApiClient.cs index 94356fb227f..ef2952a6f70 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Client/ApiClient.cs +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/Client/ApiClient.cs @@ -115,6 +115,8 @@ namespace IO.Swagger.Client String contentType) { var request = new RestRequest(path, method); + // disable ResetSharp.Portable built-in serialization + request.Serializer = null; // add path parameter, if any foreach(var param in pathParams) @@ -142,11 +144,11 @@ namespace IO.Swagger.Client { if (postBody.GetType() == typeof(String)) { - request.AddParameter("application/json", postBody, ParameterType.RequestBody); + request.AddParameter(new Parameter { Value = postBody, Type = ParameterType.RequestBody, ContentType = "application/json" }); } else if (postBody.GetType() == typeof(byte[])) { - request.AddParameter(contentType, postBody, ParameterType.RequestBody); + request.AddParameter(new Parameter { Value = postBody, Type = ParameterType.RequestBody, ContentType = contentType }); } } diff --git a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/IO.Swagger.csproj b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/IO.Swagger.csproj index 2429b4217d1..bfbb352b574 100644 --- a/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/client/petstore/csharp/SwaggerClientNetStandard/src/IO.Swagger/IO.Swagger.csproj @@ -43,7 +43,10 @@ Contact: apiteam@swagger.io - + + + + diff --git a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/IO.Swagger.csproj b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/IO.Swagger.csproj index 27f887c6aa9..3c33414c2c8 100644 --- a/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/IO.Swagger.csproj +++ b/samples/client/petstore/csharp/SwaggerClientWithPropertyChanged/src/IO.Swagger/IO.Swagger.csproj @@ -64,7 +64,10 @@ Contact: apiteam@swagger.io - + + + +