(feature): less strict default patch operation model validation
This commit is contained in:
parent
439fa6f90c
commit
56b3ce84b4
@ -11,11 +11,6 @@ public abstract class PatchRequestModelBase : RequestModelBase {
|
|||||||
|
|
||||||
public Dictionary<string, PatchOperation>? Operations { get; set; }
|
public Dictionary<string, PatchOperation>? Operations { get; set; }
|
||||||
|
|
||||||
private bool HasNonNullPatchField => GetType()
|
|
||||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
|
||||||
.Where(prop => prop.Name != nameof(Operations))
|
|
||||||
.Any(prop => prop.GetValue(this) != null);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attempts to retrieve the patch operation associated with the specified property name (case insensitive).
|
/// Attempts to retrieve the patch operation associated with the specified property name (case insensitive).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -40,10 +35,6 @@ public abstract class PatchRequestModelBase : RequestModelBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
public override IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
|
||||||
if (!HasNonNullPatchField) {
|
|
||||||
yield return new ValidationResult("At least one patch field must be provided", ["PatchField"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Operations != null) {
|
if (Operations != null) {
|
||||||
foreach (var operation in Operations) {
|
foreach (var operation in Operations) {
|
||||||
if (!Enum.IsDefined(typeof(PatchOperation), operation.Value)) {
|
if (!Enum.IsDefined(typeof(PatchOperation), operation.Value)) {
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<!-- NuGet package metadata -->
|
<!-- NuGet package metadata -->
|
||||||
<PackageId>MaksIT.Core</PackageId>
|
<PackageId>MaksIT.Core</PackageId>
|
||||||
<Version>1.4.3</Version>
|
<Version>1.4.4</Version>
|
||||||
<Authors>Maksym Sadovnychyy</Authors>
|
<Authors>Maksym Sadovnychyy</Authors>
|
||||||
<Company>MAKS-IT</Company>
|
<Company>MAKS-IT</Company>
|
||||||
<Product>MaksIT.Core</Product>
|
<Product>MaksIT.Core</Product>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user