From 589eb9c02e066ba03a6e0a8a4c93602dad51d74d Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 25 Sep 2023 19:38:41 +0200 Subject: [PATCH] remove enum handling --- .../Generation/EnumHandling.cs | 23 ------- .../NewtonsoftJsonSchemaGeneratorSettings.cs | 62 ------------------- 2 files changed, 85 deletions(-) delete mode 100644 src/NJsonSchema.NewtonsoftJson/Generation/EnumHandling.cs diff --git a/src/NJsonSchema.NewtonsoftJson/Generation/EnumHandling.cs b/src/NJsonSchema.NewtonsoftJson/Generation/EnumHandling.cs deleted file mode 100644 index 2e807fe5e..000000000 --- a/src/NJsonSchema.NewtonsoftJson/Generation/EnumHandling.cs +++ /dev/null @@ -1,23 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (c) Rico Suter. All rights reserved. -// -// https://github.com/RicoSuter/NJsonSchema/blob/master/LICENSE.md -// Rico Suter, mail@rsuter.com -//----------------------------------------------------------------------- - -namespace NJsonSchema.Generation -{ - /// Defines the enum handling. - public enum EnumHandling - { - /// Generates an integer field without enumeration (except when using StringEnumConverter). - Integer, - - /// Generates a string field with JSON Schema enumeration. - String, - - /// Generates a camel-cased string field with JSON Schema enumeration. - CamelCaseString, - } -} \ No newline at end of file diff --git a/src/NJsonSchema.NewtonsoftJson/Generation/NewtonsoftJsonSchemaGeneratorSettings.cs b/src/NJsonSchema.NewtonsoftJson/Generation/NewtonsoftJsonSchemaGeneratorSettings.cs index da10c1e05..827633502 100644 --- a/src/NJsonSchema.NewtonsoftJson/Generation/NewtonsoftJsonSchemaGeneratorSettings.cs +++ b/src/NJsonSchema.NewtonsoftJson/Generation/NewtonsoftJsonSchemaGeneratorSettings.cs @@ -11,7 +11,6 @@ using System.Reflection; using Newtonsoft.Json.Serialization; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace NJsonSchema.Generation { @@ -20,8 +19,6 @@ public class NewtonsoftJsonSchemaGeneratorSettings : JsonSchemaGeneratorSettings { private Dictionary _cachedContracts = new Dictionary(); - private EnumHandling _defaultEnumHandling; - private PropertyNameHandling _defaultPropertyNameHandling; private JsonSerializerSettings _serializerSettings; /// Initializes a new instance of the class. @@ -29,11 +26,6 @@ public NewtonsoftJsonSchemaGeneratorSettings() { ReflectionService = new NewtonsoftJsonReflectionService(); SerializerSettings = new JsonSerializerSettings(); - -#pragma warning disable CS0618 - DefaultEnumHandling = EnumHandling.Integer; - DefaultPropertyNameHandling = PropertyNameHandling.Default; -#pragma warning restore CS0618 } /// Gets or sets the Newtonsoft JSON serializer settings. @@ -47,28 +39,6 @@ public JsonSerializerSettings SerializerSettings } } - /// Gets or sets the default property name handling (default: Default). - [Obsolete("Use SerializerSettings directly instead. In NSwag.AspNetCore the property is set automatically.")] - public PropertyNameHandling DefaultPropertyNameHandling - { - get => _defaultPropertyNameHandling; set - { - _defaultPropertyNameHandling = value; - UpdateActualContractResolverAndSerializerSettings(); - } - } - - /// Gets or sets the default enum handling (default: Integer). - [Obsolete("Use SerializerSettings directly instead. In NSwag.AspNetCore the property is set automatically.")] - public EnumHandling DefaultEnumHandling - { - get => _defaultEnumHandling; set - { - _defaultEnumHandling = value; - UpdateActualSerializerSettings(); - } - } - /// Gets the contract resolver. /// The contract resolver. /// A setting is misconfigured. @@ -101,37 +71,5 @@ public JsonContract ResolveContract(Type type) return _cachedContracts[key]; } - -#pragma warning disable CS0618 - private void UpdateActualContractResolverAndSerializerSettings() - { - _cachedContracts = new Dictionary(); - - if (DefaultPropertyNameHandling == PropertyNameHandling.CamelCase) - { - SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy(false, true) }; - } - else if (DefaultPropertyNameHandling == PropertyNameHandling.SnakeCase) - { - SerializerSettings.ContractResolver = new DefaultContractResolver { NamingStrategy = new SnakeCaseNamingStrategy(false, true) }; - } - - UpdateActualSerializerSettings(); - } - - private void UpdateActualSerializerSettings() - { - if (DefaultEnumHandling == EnumHandling.String) - { - SerializerSettings.Converters.Add(new StringEnumConverter()); - } - else if (DefaultEnumHandling == EnumHandling.CamelCaseString) - { - SerializerSettings.Converters.Add(new StringEnumConverter(true)); - } - - _cachedContracts.Clear(); - } -#pragma warning restore CS0618 } } \ No newline at end of file