diff --git a/src/Tingle.AspNetCore.JsonPatch/Converters/JsonPatchMergeDocumentConverter.cs b/src/Tingle.AspNetCore.JsonPatch/Converters/JsonMergePatchDocumentConverter.cs similarity index 81% rename from src/Tingle.AspNetCore.JsonPatch/Converters/JsonPatchMergeDocumentConverter.cs rename to src/Tingle.AspNetCore.JsonPatch/Converters/JsonMergePatchDocumentConverter.cs index 901ee84..0b58ac7 100644 --- a/src/Tingle.AspNetCore.JsonPatch/Converters/JsonPatchMergeDocumentConverter.cs +++ b/src/Tingle.AspNetCore.JsonPatch/Converters/JsonMergePatchDocumentConverter.cs @@ -4,13 +4,13 @@ namespace Tingle.AspNetCore.JsonPatch.Converters; -public class JsonPatchMergeDocumentConverter : JsonConverter +public class JsonMergePatchDocumentConverter : JsonConverter { /// - public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(JsonPatchMergeDocument); + public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(JsonMergePatchDocument); /// - public override JsonPatchMergeDocument? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override JsonMergePatchDocument? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType == JsonTokenType.Null) return default; if (reader.TokenType is not JsonTokenType.StartObject) @@ -21,13 +21,13 @@ public class JsonPatchMergeDocumentConverter : JsonConverter(); - JsonPatchMergeDocumentConverterHelper.PopulateOperations(operations, node); + JsonMergePatchDocumentConverterHelper.PopulateOperations(operations, node); - return new JsonPatchMergeDocument(operations, options); + return new JsonMergePatchDocument(operations, options); } /// - public override void Write(Utf8JsonWriter writer, JsonPatchMergeDocument value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, JsonMergePatchDocument value, JsonSerializerOptions options) { // convert the operations to a JSON object var operations = value.Operations ?? []; @@ -39,7 +39,7 @@ public override void Write(Utf8JsonWriter writer, JsonPatchMergeDocument value, if (type is Operations.OperationType.Add or Operations.OperationType.Replace) { var segments = operation.path.Trim('/').Split('/'); - JsonPatchMergeDocumentConverterHelper.PopulateJsonObject(node, segments, operation.value, options); + JsonMergePatchDocumentConverterHelper.PopulateJsonObject(node, segments, operation.value, options); } } @@ -48,13 +48,13 @@ public override void Write(Utf8JsonWriter writer, JsonPatchMergeDocument value, } } -public class JsonPatchMergeDocumentConverter : JsonConverter> where TModel : class +public class JsonMergePatchDocumentConverter : JsonConverter> where TModel : class { /// - public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(JsonPatchMergeDocument); + public override bool CanConvert(Type typeToConvert) => typeToConvert == typeof(JsonMergePatchDocument); /// - public override JsonPatchMergeDocument? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override JsonMergePatchDocument? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType == JsonTokenType.Null) return default; if (reader.TokenType is not JsonTokenType.StartObject) @@ -65,13 +65,13 @@ public class JsonPatchMergeDocumentConverter : JsonConverter>(); - JsonPatchMergeDocumentConverterHelper.PopulateOperations(operations, node); + JsonMergePatchDocumentConverterHelper.PopulateOperations(operations, node); - return new JsonPatchMergeDocument(operations, options); + return new JsonMergePatchDocument(operations, options); } /// - public override void Write(Utf8JsonWriter writer, JsonPatchMergeDocument value, JsonSerializerOptions options) + public override void Write(Utf8JsonWriter writer, JsonMergePatchDocument value, JsonSerializerOptions options) { // convert the operations to a JSON object var operations = value.Operations ?? []; @@ -82,7 +82,7 @@ public override void Write(Utf8JsonWriter writer, JsonPatchMergeDocument var type = operation.OperationType; var segments = operation.path.Trim('/').Split('/'); var opvalue = type is Operations.OperationType.Remove ? null : operation.value; - JsonPatchMergeDocumentConverterHelper.PopulateJsonObject(node, segments, opvalue, options); + JsonMergePatchDocumentConverterHelper.PopulateJsonObject(node, segments, opvalue, options); } // write the object @@ -90,7 +90,7 @@ public override void Write(Utf8JsonWriter writer, JsonPatchMergeDocument } } -internal static class JsonPatchMergeDocumentConverterHelper +internal static class JsonMergePatchDocumentConverterHelper { internal static void PopulateJsonObject(JsonObject node, IReadOnlyList segments, object? value, JsonSerializerOptions options) { diff --git a/src/Tingle.AspNetCore.JsonPatch/Converters/TypedJsonPatchMergeDocumentConverter.cs b/src/Tingle.AspNetCore.JsonPatch/Converters/TypedJsonMergePatchDocumentConverter.cs similarity index 74% rename from src/Tingle.AspNetCore.JsonPatch/Converters/TypedJsonPatchMergeDocumentConverter.cs rename to src/Tingle.AspNetCore.JsonPatch/Converters/TypedJsonMergePatchDocumentConverter.cs index b02edce..9e1598b 100644 --- a/src/Tingle.AspNetCore.JsonPatch/Converters/TypedJsonPatchMergeDocumentConverter.cs +++ b/src/Tingle.AspNetCore.JsonPatch/Converters/TypedJsonMergePatchDocumentConverter.cs @@ -3,17 +3,17 @@ namespace Tingle.AspNetCore.JsonPatch.Converters; -internal class TypedJsonPatchMergeDocumentConverter : JsonConverterFactory +internal class TypedJsonMergePatchDocumentConverter : JsonConverterFactory { public override bool CanConvert(Type typeToConvert) { - return typeToConvert.IsGenericType && typeToConvert.GetGenericTypeDefinition() == typeof(JsonPatchMergeDocument<>); + return typeToConvert.IsGenericType && typeToConvert.GetGenericTypeDefinition() == typeof(JsonMergePatchDocument<>); } public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) { var modelType = typeToConvert.GetGenericArguments()[0]; - var conveterType = typeof(JsonPatchMergeDocumentConverter<>).MakeGenericType(modelType); + var conveterType = typeof(JsonMergePatchDocumentConverter<>).MakeGenericType(modelType); return (JsonConverter?)Activator.CreateInstance(conveterType); } } diff --git a/src/Tingle.AspNetCore.JsonPatch/IJsonPatchMergeDocument.cs b/src/Tingle.AspNetCore.JsonPatch/IJsonMergePatchDocument.cs similarity index 83% rename from src/Tingle.AspNetCore.JsonPatch/IJsonPatchMergeDocument.cs rename to src/Tingle.AspNetCore.JsonPatch/IJsonMergePatchDocument.cs index 549f8f5..a289707 100644 --- a/src/Tingle.AspNetCore.JsonPatch/IJsonPatchMergeDocument.cs +++ b/src/Tingle.AspNetCore.JsonPatch/IJsonMergePatchDocument.cs @@ -3,7 +3,7 @@ namespace Tingle.AspNetCore.JsonPatch; -public interface IJsonPatchMergeDocument +public interface IJsonMergePatchDocument { JsonSerializerOptions SerializerOptions { get; set; } diff --git a/src/Tingle.AspNetCore.JsonPatch/IMvcBuilderExtensions.cs b/src/Tingle.AspNetCore.JsonPatch/IMvcBuilderExtensions.cs index b19e5f8..b39800e 100644 --- a/src/Tingle.AspNetCore.JsonPatch/IMvcBuilderExtensions.cs +++ b/src/Tingle.AspNetCore.JsonPatch/IMvcBuilderExtensions.cs @@ -23,7 +23,7 @@ public static IMvcBuilder AddJsonPatch(this IMvcBuilder builder) ServiceDescriptor.Transient()); services.TryAddEnumerable( - ServiceDescriptor.Transient()); + ServiceDescriptor.Transient()); services.TryAddEnumerable( ServiceDescriptor.Transient, JsonPatchMvcOptionsSetup>()); @@ -55,9 +55,9 @@ public void Configure(MvcOptions options) options.InputFormatters.Insert( 0, - new SystemTextJsonPatchMergeInputFormatter( + new SystemTextJsonMergePatchInputFormatter( jsonOptions, - loggerFactory.CreateLogger())); + loggerFactory.CreateLogger())); } } } diff --git a/src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocument.cs b/src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocument.cs similarity index 67% rename from src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocument.cs rename to src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocument.cs index 9010861..98d9da6 100644 --- a/src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocument.cs +++ b/src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocument.cs @@ -6,30 +6,30 @@ namespace Tingle.AspNetCore.JsonPatch; -[JsonConverter(typeof(JsonPatchMergeDocumentConverter))] -public class JsonPatchMergeDocument(JsonPatchDocument inner) : IJsonPatchMergeDocument +[JsonConverter(typeof(JsonMergePatchDocumentConverter))] +public class JsonMergePatchDocument(JsonPatchDocument inner) : IJsonMergePatchDocument { private readonly JsonPatchDocument inner = inner ?? throw new ArgumentNullException(nameof(inner)); [JsonIgnore] public JsonSerializerOptions SerializerOptions { get { return inner.SerializerOptions; } set { inner.SerializerOptions = value; } } - public JsonPatchMergeDocument() : this([]) { } + public JsonMergePatchDocument() : this([]) { } - public JsonPatchMergeDocument(List operations) : this(operations, new()) { } + public JsonMergePatchDocument(List operations) : this(operations, new()) { } - public JsonPatchMergeDocument(JsonSerializerOptions serializerOptions) : this([], serializerOptions) { } + public JsonMergePatchDocument(JsonSerializerOptions serializerOptions) : this([], serializerOptions) { } - public JsonPatchMergeDocument(List operations, JsonSerializerOptions serializerOptions) + public JsonMergePatchDocument(List operations, JsonSerializerOptions serializerOptions) : this(new JsonPatchDocument(operations, serializerOptions)) { } internal List Operations => inner.Operations; - IList IJsonPatchMergeDocument.GetOperations() => ((IJsonPatchDocument)inner).GetOperations(); + IList IJsonMergePatchDocument.GetOperations() => ((IJsonPatchDocument)inner).GetOperations(); /// - /// Apply this JsonPatchMergeDocument + /// Apply this JsonMergePatchDocument /// - /// Object to apply the JsonPatchMergeDocument to + /// Object to apply the JsonMergePatchDocument to public void ApplyTo(object objectToApplyTo) { ArgumentNullException.ThrowIfNull(objectToApplyTo); @@ -38,9 +38,9 @@ public void ApplyTo(object objectToApplyTo) } /// - /// Apply this JsonPatchMergeDocument + /// Apply this JsonMergePatchDocument /// - /// Object to apply the JsonPatchMergeDocument to + /// Object to apply the JsonMergePatchDocument to /// Action to log errors public void ApplyTo(object objectToApplyTo, Action logErrorAction) { @@ -48,17 +48,17 @@ public void ApplyTo(object objectToApplyTo, Action logErrorActio } /// - /// Apply this JsonPatchMergeDocument + /// Apply this JsonMergePatchDocument /// - /// Object to apply the JsonPatchMergeDocument to + /// Object to apply the JsonMergePatchDocument to /// IObjectAdapter instance to use when applying /// Action to log errors public void ApplyTo(object objectToApplyTo, IObjectAdapter adapter, Action logErrorAction) => inner.ApplyTo(objectToApplyTo, adapter, logErrorAction); /// - /// Apply this JsonPatchMergeDocument + /// Apply this JsonMergePatchDocument /// - /// Object to apply the JsonPatchMergeDocument to + /// Object to apply the JsonMergePatchDocument to /// IObjectAdapter instance to use when applying public void ApplyTo(object objectToApplyTo, IObjectAdapter adapter) => inner.ApplyTo(objectToApplyTo, adapter); } diff --git a/src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocumentExtensions.cs b/src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocumentExtensions.cs similarity index 87% rename from src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocumentExtensions.cs rename to src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocumentExtensions.cs index d3f98e4..7899e36 100644 --- a/src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocumentExtensions.cs +++ b/src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocumentExtensions.cs @@ -4,19 +4,19 @@ namespace Tingle.AspNetCore.JsonPatch; /// -/// Extensions for +/// Extensions for /// -public static class JsonPatchMergeDocumentExtensions +public static class JsonMergePatchDocumentExtensions { /// /// Applies JSON patch operations on object and logs errors in . /// /// - /// The . - /// The entity on which is applied. + /// The . + /// The entity on which is applied. /// The to add errors. /// The properties that are not allowed to changed - public static void ApplyToSafely(this JsonPatchMergeDocument patchDoc, + public static void ApplyToSafely(this JsonMergePatchDocument patchDoc, T objectToApplyTo, ModelStateDictionary modelState, IEnumerable immutableProperties) @@ -39,12 +39,12 @@ public static void ApplyToSafely(this JsonPatchMergeDocument patchDoc, /// Applies JSON patch operations on object and logs errors in . /// /// - /// The . - /// The entity on which is applied. + /// The . + /// The entity on which is applied. /// The to add errors. /// The prefix to use when looking up values in . /// The properties that are not allowed to changed - public static void ApplyToSafely(this JsonPatchMergeDocument patchDoc, + public static void ApplyToSafely(this JsonMergePatchDocument patchDoc, T objectToApplyTo, ModelStateDictionary modelState, string prefix, @@ -82,10 +82,10 @@ public static void ApplyToSafely(this JsonPatchMergeDocument patchDoc, /// Applies JSON patch operations on object and logs errors in . /// /// - /// The . - /// The entity on which is applied. + /// The . + /// The entity on which is applied. /// The to add errors. - public static void ApplyToSafely(this JsonPatchMergeDocument patchDoc, + public static void ApplyToSafely(this JsonMergePatchDocument patchDoc, T objectToApplyTo, ModelStateDictionary modelState) where T : class @@ -103,11 +103,11 @@ public static void ApplyToSafely(this JsonPatchMergeDocument patchDoc, /// Applies JSON patch operations on object and logs errors in . /// /// - /// The . - /// The entity on which is applied. + /// The . + /// The entity on which is applied. /// The to add errors. /// The prefix to use when looking up values in . - public static void ApplyToSafely(this JsonPatchMergeDocument patchDoc, + public static void ApplyToSafely(this JsonMergePatchDocument patchDoc, T objectToApplyTo, ModelStateDictionary modelState, string prefix) @@ -149,10 +149,10 @@ public static void ApplyToSafely(this JsonPatchMergeDocument patchDoc, /// /// Applies JSON patch operations on object and logs errors in . /// - /// The . - /// The entity on which is applied. + /// The . + /// The entity on which is applied. /// The to add errors. - public static void ApplyTo(this JsonPatchMergeDocument patchDoc, T objectToApplyTo, ModelStateDictionary modelState) where T : class + public static void ApplyTo(this JsonMergePatchDocument patchDoc, T objectToApplyTo, ModelStateDictionary modelState) where T : class { ArgumentNullException.ThrowIfNull(patchDoc); ArgumentNullException.ThrowIfNull(objectToApplyTo); @@ -164,11 +164,11 @@ public static void ApplyTo(this JsonPatchMergeDocument patchDoc, T objectT /// /// Applies JSON patch operations on object and logs errors in . /// - /// The . - /// The entity on which is applied. + /// The . + /// The entity on which is applied. /// The to add errors. /// The prefix to use when looking up values in . - public static void ApplyTo(this JsonPatchMergeDocument patchDoc, T objectToApplyTo, ModelStateDictionary modelState, string prefix) where T : class + public static void ApplyTo(this JsonMergePatchDocument patchDoc, T objectToApplyTo, ModelStateDictionary modelState, string prefix) where T : class { ArgumentNullException.ThrowIfNull(patchDoc); ArgumentNullException.ThrowIfNull(objectToApplyTo); diff --git a/src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocumentOfT.cs b/src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocumentOfT.cs similarity index 66% rename from src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocumentOfT.cs rename to src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocumentOfT.cs index c582106..7ac49b3 100644 --- a/src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocumentOfT.cs +++ b/src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocumentOfT.cs @@ -6,30 +6,30 @@ namespace Tingle.AspNetCore.JsonPatch; -[JsonConverter(typeof(TypedJsonPatchMergeDocumentConverter))] -public class JsonPatchMergeDocument(JsonPatchDocument inner) : IJsonPatchMergeDocument where TModel : class +[JsonConverter(typeof(TypedJsonMergePatchDocumentConverter))] +public class JsonMergePatchDocument(JsonPatchDocument inner) : IJsonMergePatchDocument where TModel : class { private readonly JsonPatchDocument inner = inner ?? throw new ArgumentNullException(nameof(inner)); [JsonIgnore] public JsonSerializerOptions SerializerOptions { get { return inner.SerializerOptions; } set { inner.SerializerOptions = value; } } - public JsonPatchMergeDocument() : this([]) { } + public JsonMergePatchDocument() : this([]) { } - public JsonPatchMergeDocument(List> operations) : this(operations, new()) { } + public JsonMergePatchDocument(List> operations) : this(operations, new()) { } - public JsonPatchMergeDocument(JsonSerializerOptions serializerOptions) : this([], serializerOptions) { } + public JsonMergePatchDocument(JsonSerializerOptions serializerOptions) : this([], serializerOptions) { } - public JsonPatchMergeDocument(List> operations, JsonSerializerOptions serializerOptions) + public JsonMergePatchDocument(List> operations, JsonSerializerOptions serializerOptions) : this(new JsonPatchDocument(operations, serializerOptions)) { } internal List> Operations => inner.Operations; - IList IJsonPatchMergeDocument.GetOperations() => ((IJsonPatchDocument)inner).GetOperations(); + IList IJsonMergePatchDocument.GetOperations() => ((IJsonPatchDocument)inner).GetOperations(); /// - /// Apply this JsonPatchMergeDocument + /// Apply this JsonMergePatchDocument /// - /// Object to apply the JsonPatchMergeDocument to + /// Object to apply the JsonMergePatchDocument to public void ApplyTo(TModel objectToApplyTo) { ArgumentNullException.ThrowIfNull(objectToApplyTo); @@ -38,9 +38,9 @@ public void ApplyTo(TModel objectToApplyTo) } /// - /// Apply this JsonPatchMergeDocument + /// Apply this JsonMergePatchDocument /// - /// Object to apply the JsonPatchMergeDocument to + /// Object to apply the JsonMergePatchDocument to /// Action to log errors public void ApplyTo(TModel objectToApplyTo, Action logErrorAction) { @@ -48,17 +48,17 @@ public void ApplyTo(TModel objectToApplyTo, Action logErrorActio } /// - /// Apply this JsonPatchMergeDocument + /// Apply this JsonMergePatchDocument /// - /// Object to apply the JsonPatchMergeDocument to + /// Object to apply the JsonMergePatchDocument to /// IObjectAdapter instance to use when applying /// Action to log errors public void ApplyTo(TModel objectToApplyTo, IObjectAdapter adapter, Action logErrorAction) => inner.ApplyTo(objectToApplyTo, adapter, logErrorAction); /// - /// Apply this JsonPatchMergeDocument + /// Apply this JsonMergePatchDocument /// - /// Object to apply the JsonPatchMergeDocument to + /// Object to apply the JsonMergePatchDocument to /// IObjectAdapter instance to use when applying public void ApplyTo(TModel objectToApplyTo, IObjectAdapter adapter) => inner.ApplyTo(objectToApplyTo, adapter); } diff --git a/src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocumentProvider.cs b/src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocumentProvider.cs similarity index 88% rename from src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocumentProvider.cs rename to src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocumentProvider.cs index e66a998..de3a5f8 100644 --- a/src/Tingle.AspNetCore.JsonPatch/JsonPatchMergeDocumentProvider.cs +++ b/src/Tingle.AspNetCore.JsonPatch/JsonMergePatchDocumentProvider.cs @@ -5,10 +5,10 @@ namespace Tingle.AspNetCore.JsonPatch; /// /// Implements a provider of to change parameters of -/// type to the model type. +/// type to the model type. /// /// The . -internal sealed class JsonPatchMergeDocumentProvider(IModelMetadataProvider modelMetadataProvider) : IApiDescriptionProvider +internal sealed class JsonMergePatchDocumentProvider(IModelMetadataProvider modelMetadataProvider) : IApiDescriptionProvider { /// /// @@ -26,7 +26,7 @@ public void OnProvidersExecuting(ApiDescriptionProviderContext context) foreach (var parameterDescription in result.ParameterDescriptions) { var parameterType = parameterDescription.Type; - if (parameterType.IsGenericType && parameterType.GetGenericTypeDefinition() == typeof(JsonPatchMergeDocument<>)) + if (parameterType.IsGenericType && parameterType.GetGenericTypeDefinition() == typeof(JsonMergePatchDocument<>)) { var modelType = parameterType.GetGenericArguments()[0]; diff --git a/src/Tingle.AspNetCore.JsonPatch/MediaTypeHeaderValues.cs b/src/Tingle.AspNetCore.JsonPatch/MediaTypeHeaderValues.cs index 4b1165f..19fc954 100644 --- a/src/Tingle.AspNetCore.JsonPatch/MediaTypeHeaderValues.cs +++ b/src/Tingle.AspNetCore.JsonPatch/MediaTypeHeaderValues.cs @@ -7,6 +7,6 @@ internal static class MediaTypeHeaderValues public static readonly MediaTypeHeaderValue ApplicationJsonPatch = MediaTypeHeaderValue.Parse("application/json-patch+json").CopyAsReadOnly(); - public static readonly MediaTypeHeaderValue ApplicationJsonPatchMerge + public static readonly MediaTypeHeaderValue ApplicationJsonMergePatch = MediaTypeHeaderValue.Parse("application/merge-patch+json").CopyAsReadOnly(); } diff --git a/src/Tingle.AspNetCore.JsonPatch/README.md b/src/Tingle.AspNetCore.JsonPatch/README.md index 50f4ff6..600c2f1 100644 --- a/src/Tingle.AspNetCore.JsonPatch/README.md +++ b/src/Tingle.AspNetCore.JsonPatch/README.md @@ -102,7 +102,7 @@ Use in your controller ```cs [HttpPatch] -public void Patch([FromBody] JsonPatchMergeDocument patch) +public void Patch([FromBody] JsonMergePatchDocument patch) { ... patch.ApplyTo(customer, ModelState); diff --git a/src/Tingle.AspNetCore.JsonPatch/SystemTextJsonPatchMergeInputFormatter.cs b/src/Tingle.AspNetCore.JsonPatch/SystemTextJsonMergePatchInputFormatter.cs similarity index 72% rename from src/Tingle.AspNetCore.JsonPatch/SystemTextJsonPatchMergeInputFormatter.cs rename to src/Tingle.AspNetCore.JsonPatch/SystemTextJsonMergePatchInputFormatter.cs index e0a07cf..f206526 100644 --- a/src/Tingle.AspNetCore.JsonPatch/SystemTextJsonPatchMergeInputFormatter.cs +++ b/src/Tingle.AspNetCore.JsonPatch/SystemTextJsonMergePatchInputFormatter.cs @@ -4,19 +4,19 @@ namespace Tingle.AspNetCore.JsonPatch; -internal class SystemTextJsonPatchMergeInputFormatter : SystemTextJsonInputFormatter, IInputFormatterExceptionPolicy +internal class SystemTextJsonMergePatchInputFormatter : SystemTextJsonInputFormatter, IInputFormatterExceptionPolicy { /// - /// Initializes a new instance of . + /// Initializes a new instance of . /// /// The . /// The . - public SystemTextJsonPatchMergeInputFormatter(JsonOptions options, ILogger logger) : base(options, logger) + public SystemTextJsonMergePatchInputFormatter(JsonOptions options, ILogger logger) : base(options, logger) { // Clear all values and only include merge-patch+json value. SupportedMediaTypes.Clear(); - SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJsonPatchMerge); + SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationJsonMergePatch); } /// @@ -24,7 +24,7 @@ public virtual InputFormatterExceptionPolicy ExceptionPolicy { get { - if (GetType() == typeof(SystemTextJsonPatchMergeInputFormatter)) + if (GetType() == typeof(SystemTextJsonMergePatchInputFormatter)) { return InputFormatterExceptionPolicy.MalformedInputExceptions; } @@ -40,9 +40,9 @@ public override async Task ReadRequestBodyAsync(InputForma var result = await base.ReadRequestBodyAsync(context).ConfigureAwait(false); if (!result.HasError) { - if (result.Model is IJsonPatchMergeDocument jsonPatchMergeDocument && SerializerOptions is not null) + if (result.Model is IJsonMergePatchDocument jsonMergePatchDocument && SerializerOptions is not null) { - jsonPatchMergeDocument.SerializerOptions = SerializerOptions; + jsonMergePatchDocument.SerializerOptions = SerializerOptions; } } @@ -55,7 +55,7 @@ public override bool CanRead(InputFormatterContext context) ArgumentNullException.ThrowIfNull(context); var modelType = context.ModelType; - if (!typeof(IJsonPatchMergeDocument).IsAssignableFrom(modelType) || + if (!typeof(IJsonMergePatchDocument).IsAssignableFrom(modelType) || !modelType.IsGenericType) { return false; diff --git a/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonPatchMergeDocumentConverterHelperTests.cs b/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonMergePatchDocumentConverterHelperTests.cs similarity index 95% rename from tests/Tingle.AspNetCore.JsonPatch.Tests/JsonPatchMergeDocumentConverterHelperTests.cs rename to tests/Tingle.AspNetCore.JsonPatch.Tests/JsonMergePatchDocumentConverterHelperTests.cs index a3c36ba..c1e108e 100644 --- a/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonPatchMergeDocumentConverterHelperTests.cs +++ b/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonMergePatchDocumentConverterHelperTests.cs @@ -4,7 +4,7 @@ namespace Tingle.AspNetCore.JsonPatch; -public class JsonPatchMergeDocumentConverterHelperTests +public class JsonMergePatchDocumentConverterHelperTests { [Fact] public void PopulateOperations_Works() @@ -30,7 +30,7 @@ public void PopulateOperations_Works() }; var operations = new List>(); - JsonPatchMergeDocumentConverterHelper.PopulateOperations(operations, node); + JsonMergePatchDocumentConverterHelper.PopulateOperations(operations, node); Assert.Equal([ "add", @@ -96,7 +96,7 @@ public void PopulateJsonObject_Works() var type = operation.OperationType; var segments = operation.path.Trim('/').Split('/'); ; var opvalue = type is Operations.OperationType.Remove ? null : operation.value; - JsonPatchMergeDocumentConverterHelper.PopulateJsonObject(node, segments, opvalue, serializerOptions); + JsonMergePatchDocumentConverterHelper.PopulateJsonObject(node, segments, opvalue, serializerOptions); } var expected = new JsonObject @@ -147,7 +147,7 @@ public void Apply_Works() var video = new Video { Metadata = new() { ["primary"] = "cake", } }; var serializerOptions = new JsonSerializerOptions(JsonSerializerDefaults.Web); - var doc = JsonSerializer.Deserialize>(node.ToJsonString(), serializerOptions)!; + var doc = JsonSerializer.Deserialize>(node.ToJsonString(), serializerOptions)!; doc.ApplyTo(video); Assert.Equal("rudi shule", Assert.Contains("swa", video.Translations).Body); diff --git a/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonPatchMergeDocumentExtensionsTest.cs b/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonMergePatchDocumentExtensionsTest.cs similarity index 86% rename from tests/Tingle.AspNetCore.JsonPatch.Tests/JsonPatchMergeDocumentExtensionsTest.cs rename to tests/Tingle.AspNetCore.JsonPatch.Tests/JsonMergePatchDocumentExtensionsTest.cs index 7774521..8ca521a 100644 --- a/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonPatchMergeDocumentExtensionsTest.cs +++ b/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonMergePatchDocumentExtensionsTest.cs @@ -3,14 +3,14 @@ namespace Tingle.AspNetCore.JsonPatch; -public class JsonPatchMergeDocumentExtensionsTest +public class JsonMergePatchDocumentExtensionsTest { [Fact] - public void ApplyTo_JsonPatchMergeDocument_ModelState() + public void ApplyTo_JsonMergePatchDocument_ModelState() { // Arrange var operation = new Operation("add", "CustomerId", from: null, value: "TestName"); - var patchDoc = new JsonPatchMergeDocument(); + var patchDoc = new JsonMergePatchDocument(); patchDoc.Operations.Add(operation); var modelState = new ModelStateDictionary(); @@ -24,11 +24,11 @@ public void ApplyTo_JsonPatchMergeDocument_ModelState() } [Fact] - public void ApplyTo_JsonPatchMergeDocument_PrefixModelState() + public void ApplyTo_JsonMergePatchDocument_PrefixModelState() { // Arrange var operation = new Operation("add", "CustomerId", from: null, value: "TestName"); - var patchDoc = new JsonPatchMergeDocument(); + var patchDoc = new JsonMergePatchDocument(); patchDoc.Operations.Add(operation); var modelState = new ModelStateDictionary(); @@ -45,7 +45,7 @@ public void ApplyTo_JsonPatchMergeDocument_PrefixModelState() public void ApplyTo_ValidPatchOperation_NoErrorsAdded() { // Arrange - var patch = new JsonPatchMergeDocument(); + var patch = new JsonMergePatchDocument(); patch.Operations.Add(new Operation("replace", "/CustomerName", null, "James")); var model = new Customer(); var modelState = new ModelStateDictionary(); @@ -70,7 +70,7 @@ public void ApplyTo_InvalidPatchOperations_AddsModelStateError( string error) { // Arrange - var patch = new JsonPatchMergeDocument(); + var patch = new JsonMergePatchDocument(); patch.Operations.Add(new Operation(op, path, from, value)); var model = new Customer(); var modelState = new ModelStateDictionary(); diff --git a/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonPatchMergeDocumentProviderTests.cs b/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonMergePatchDocumentProviderTests.cs similarity index 83% rename from tests/Tingle.AspNetCore.JsonPatch.Tests/JsonPatchMergeDocumentProviderTests.cs rename to tests/Tingle.AspNetCore.JsonPatch.Tests/JsonMergePatchDocumentProviderTests.cs index 7ca104a..c1096e3 100644 --- a/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonPatchMergeDocumentProviderTests.cs +++ b/tests/Tingle.AspNetCore.JsonPatch.Tests/JsonMergePatchDocumentProviderTests.cs @@ -4,17 +4,17 @@ namespace Tingle.AspNetCore.JsonPatch; -public class JsonPatchMergeDocumentProviderTests +public class JsonMergePatchDocumentProviderTests { [Fact] public void OnProvidersExecuting_FindsJsonPatchDocuments_ProvidesOperationsArray() { // Arrange var metadataProvider = new EmptyModelMetadataProvider(); - var provider = new JsonPatchMergeDocumentProvider(metadataProvider); - var jsonPatchMergeParameterDescription = new ApiParameterDescription + var provider = new JsonMergePatchDocumentProvider(metadataProvider); + var jsonMergePatchParameterDescription = new ApiParameterDescription { - Type = typeof(JsonPatchMergeDocument) + Type = typeof(JsonMergePatchDocument) }; var stringParameterDescription = new ApiParameterDescription @@ -23,7 +23,7 @@ public void OnProvidersExecuting_FindsJsonPatchDocuments_ProvidesOperationsArray }; var apiDescription = new ApiDescription(); - apiDescription.ParameterDescriptions.Add(jsonPatchMergeParameterDescription); + apiDescription.ParameterDescriptions.Add(jsonMergePatchParameterDescription); apiDescription.ParameterDescriptions.Add(stringParameterDescription); var actionDescriptorList = new List();