diff --git a/README.md b/README.md index 30e1872..23c8818 100644 --- a/README.md +++ b/README.md @@ -1997,7 +1997,7 @@ var patch = new SomePatchRequestModel { Username = "Updated Name" Operations = new Dictionary { - { "Username", PartchOperation.Replace } + { "Username", PartchOperation.SetField } } }; diff --git a/src/MaksIT.Core/Abstractions/Webapi/PatchRequestModelBase.cs b/src/MaksIT.Core/Abstractions/Webapi/PatchRequestModelBase.cs index 1ff17ca..d3ded78 100644 --- a/src/MaksIT.Core/Abstractions/Webapi/PatchRequestModelBase.cs +++ b/src/MaksIT.Core/Abstractions/Webapi/PatchRequestModelBase.cs @@ -23,5 +23,11 @@ public abstract class PatchRequestModelBase : RequestModelBase { if (!HasNonNullPatchField) { yield return new ValidationResult("At least one patch field must be provided", new string[] { "PatchField" }); } + + foreach (var operation in Operations) { + if (!Enum.IsDefined(typeof(PatchOperation), operation.Value)) { + yield return new ValidationResult($"Invalid patch operation '{operation.Value}' for property '{operation.Key}'", new string[] { operation.Key }); + } + } } } diff --git a/src/MaksIT.Core/MaksIT.Core.csproj b/src/MaksIT.Core/MaksIT.Core.csproj index 64ea5c5..d8e068c 100644 --- a/src/MaksIT.Core/MaksIT.Core.csproj +++ b/src/MaksIT.Core/MaksIT.Core.csproj @@ -8,7 +8,7 @@ MaksIT.Core - 1.2.3 + 1.2.4 Maksym Sadovnychyy MAKS-IT MaksIT.Core diff --git a/src/MaksIT.Core/Webapi/Models/PatchOperation.cs b/src/MaksIT.Core/Webapi/Models/PatchOperation.cs index cd74a68..a8d7ba0 100644 --- a/src/MaksIT.Core/Webapi/Models/PatchOperation.cs +++ b/src/MaksIT.Core/Webapi/Models/PatchOperation.cs @@ -3,22 +3,37 @@ public enum PatchOperation { /// - /// When you need to replace some field, or relpace item in collection + /// When you need to set or replace a normal field /// - Replace, + SetField, /// - /// When you need to set some field, or add item to collection + /// When you need to set a normal field to null /// - Add, + RemoveField, /// - /// When you need to set some field to null, or remove item from collection + /// When you need to add an item to a collection /// - Remove, + AddToCollection, /// - /// When you need to clear collection + /// When you need to remove an item from a collection /// - Clear + RemoveFromCollection, + + /// + /// When you need to replace a collection + /// + ReplaceCollection, + + /// + /// When you need to clear a collection + /// + ClearCollection, + + /// + /// When you need to set a collection to null + /// + RemoveCollection }