diff --git a/modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache
index 8fbeead754b..504b5a22439 100644
--- a/modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp-netcore/ApiClient.mustache
@@ -160,6 +160,23 @@ namespace {{packageName}}.Client
{
private readonly String _baseUrl;
+ ///
+ /// Specifies the settings on a object.
+ /// These settings can be adjusted to accomodate custom serialization rules.
+ ///
+ public JsonSerializerSettings SerializerSettings { get; set; } = new JsonSerializerSettings
+ {
+ // OpenAPI generated types generally hide default constructors.
+ ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
+ ContractResolver = new DefaultContractResolver
+ {
+ NamingStrategy = new CamelCaseNamingStrategy
+ {
+ OverrideSpecifiedNames = false
+ }
+ }
+ };
+
///
/// Allows for extending request processing for generated code.
///
@@ -258,7 +275,7 @@ namespace {{packageName}}.Client
RestRequest request = new RestRequest(Method(method))
{
Resource = path,
- JsonSerializer = new CustomJsonCodec(configuration)
+ JsonSerializer = new CustomJsonCodec(SerializerSettings, configuration)
};
if (options.PathParameters != null)
@@ -406,7 +423,7 @@ namespace {{packageName}}.Client
}
else
{
- var customDeserializer = new CustomJsonCodec(configuration);
+ var customDeserializer = new CustomJsonCodec(SerializerSettings, configuration);
client.AddHandler("application/json", () => customDeserializer);
client.AddHandler("text/json", () => customDeserializer);
client.AddHandler("text/x-json", () => customDeserializer);
@@ -509,7 +526,7 @@ namespace {{packageName}}.Client
}
else
{
- var customDeserializer = new CustomJsonCodec(configuration);
+ var customDeserializer = new CustomJsonCodec(SerializerSettings, configuration);
client.AddHandler("application/json", () => customDeserializer);
client.AddHandler("text/json", () => customDeserializer);
client.AddHandler("text/x-json", () => customDeserializer);
diff --git a/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache b/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache
index 8495fb2e8a0..6d202d29055 100644
--- a/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache
@@ -30,7 +30,7 @@ namespace {{packageName}}.Client
///
{{>visibility}} partial class ApiClient
{
- private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
+ public JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
};
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/ApiClientTests.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/ApiClientTests.cs
new file mode 100644
index 00000000000..9a001a63e0b
--- /dev/null
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools.Test/ApiClientTests.cs
@@ -0,0 +1,46 @@
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Reflection;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Serialization;
+using RestSharp;
+using Xunit;
+
+using Org.OpenAPITools.Client;
+using Org.OpenAPITools.Api;
+using Org.OpenAPITools.Model;
+
+namespace Org.OpenAPITools.Test
+{
+ ///
+ /// Class for testing ApiClient
+ ///
+ public class ApiClientTests
+ {
+ public ApiClientTests()
+ {
+ }
+
+ ///
+ /// Test GetSerializerSettingsTest
+ ///
+ [Fact]
+ public void GetSerializerSettingsTest()
+ {
+ ApiClient apiClient = new ApiClient();
+
+ var serializerSettingsPropertyInfo = typeof(ApiClient).GetProperty(nameof(ApiClient.SerializerSettings));
+
+ // Validate that we can the set the SerializerSettings (public visibility)
+ Assert.NotNull(serializerSettingsPropertyInfo?.GetSetMethod());
+
+ // Validate default serializer settings
+ Assert.NotNull(apiClient.SerializerSettings);
+ Assert.Equal(ConstructorHandling.AllowNonPublicDefaultConstructor, apiClient.SerializerSettings.ConstructorHandling);
+ Assert.False(((DefaultContractResolver)apiClient.SerializerSettings.ContractResolver).NamingStrategy.OverrideSpecifiedNames);
+ }
+ }
+}
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs
index a1d20ac483a..520896de7ea 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs
@@ -164,6 +164,23 @@ namespace Org.OpenAPITools.Client
{
private readonly String _baseUrl;
+ ///
+ /// Specifies the settings on a object.
+ /// These settings can be adjusted to accomodate custom serialization rules.
+ ///
+ public JsonSerializerSettings SerializerSettings { get; set; } = new JsonSerializerSettings
+ {
+ // OpenAPI generated types generally hide default constructors.
+ ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
+ ContractResolver = new DefaultContractResolver
+ {
+ NamingStrategy = new CamelCaseNamingStrategy
+ {
+ OverrideSpecifiedNames = false
+ }
+ }
+ };
+
///
/// Allows for extending request processing for generated code.
///
@@ -262,7 +279,7 @@ namespace Org.OpenAPITools.Client
RestRequest request = new RestRequest(Method(method))
{
Resource = path,
- JsonSerializer = new CustomJsonCodec(configuration)
+ JsonSerializer = new CustomJsonCodec(SerializerSettings, configuration)
};
if (options.PathParameters != null)
@@ -410,7 +427,7 @@ namespace Org.OpenAPITools.Client
}
else
{
- var customDeserializer = new CustomJsonCodec(configuration);
+ var customDeserializer = new CustomJsonCodec(SerializerSettings, configuration);
client.AddHandler("application/json", () => customDeserializer);
client.AddHandler("text/json", () => customDeserializer);
client.AddHandler("text/x-json", () => customDeserializer);
@@ -512,7 +529,7 @@ namespace Org.OpenAPITools.Client
}
else
{
- var customDeserializer = new CustomJsonCodec(configuration);
+ var customDeserializer = new CustomJsonCodec(SerializerSettings, configuration);
client.AddHandler("application/json", () => customDeserializer);
client.AddHandler("text/json", () => customDeserializer);
client.AddHandler("text/x-json", () => customDeserializer);
diff --git a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiClient.cs
index 41af9ac7c4b..53e4ce7fd45 100644
--- a/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiClient.cs
+++ b/samples/client/petstore/csharp-netcore/OpenAPIClientCore/src/Org.OpenAPITools/Client/ApiClient.cs
@@ -165,6 +165,23 @@ namespace Org.OpenAPITools.Client
{
private readonly String _baseUrl;
+ ///
+ /// Specifies the settings on a object.
+ /// These settings can be adjusted to accomodate custom serialization rules.
+ ///
+ public JsonSerializerSettings SerializerSettings { get; set; } = new JsonSerializerSettings
+ {
+ // OpenAPI generated types generally hide default constructors.
+ ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor,
+ ContractResolver = new DefaultContractResolver
+ {
+ NamingStrategy = new CamelCaseNamingStrategy
+ {
+ OverrideSpecifiedNames = false
+ }
+ }
+ };
+
///
/// Allows for extending request processing for generated code.
///
@@ -263,7 +280,7 @@ namespace Org.OpenAPITools.Client
RestRequest request = new RestRequest(Method(method))
{
Resource = path,
- JsonSerializer = new CustomJsonCodec(configuration)
+ JsonSerializer = new CustomJsonCodec(SerializerSettings, configuration)
};
if (options.PathParameters != null)
@@ -411,7 +428,7 @@ namespace Org.OpenAPITools.Client
}
else
{
- var customDeserializer = new CustomJsonCodec(configuration);
+ var customDeserializer = new CustomJsonCodec(SerializerSettings, configuration);
client.AddHandler("application/json", () => customDeserializer);
client.AddHandler("text/json", () => customDeserializer);
client.AddHandler("text/x-json", () => customDeserializer);
@@ -513,7 +530,7 @@ namespace Org.OpenAPITools.Client
}
else
{
- var customDeserializer = new CustomJsonCodec(configuration);
+ var customDeserializer = new CustomJsonCodec(SerializerSettings, configuration);
client.AddHandler("application/json", () => customDeserializer);
client.AddHandler("text/json", () => customDeserializer);
client.AddHandler("text/x-json", () => customDeserializer);
diff --git a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs
index 21a140ed84e..26b1205ce63 100644
--- a/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient/src/Org.OpenAPITools/Client/ApiClient.cs
@@ -29,7 +29,7 @@ namespace Org.OpenAPITools.Client
///
public partial class ApiClient
{
- private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
+ public JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
};
diff --git a/samples/client/petstore/csharp/OpenAPIClientNetStandard/src/Org.OpenAPITools/Client/ApiClient.cs b/samples/client/petstore/csharp/OpenAPIClientNetStandard/src/Org.OpenAPITools/Client/ApiClient.cs
index 3367117774f..33758aa1883 100644
--- a/samples/client/petstore/csharp/OpenAPIClientNetStandard/src/Org.OpenAPITools/Client/ApiClient.cs
+++ b/samples/client/petstore/csharp/OpenAPIClientNetStandard/src/Org.OpenAPITools/Client/ApiClient.cs
@@ -29,7 +29,7 @@ namespace Org.OpenAPITools.Client
///
public partial class ApiClient
{
- private JsonSerializerSettings serializerSettings = new JsonSerializerSettings
+ public JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor
};