/JsonPatch.Restrict

Extends the Microsoft.AspNetCore.JsonPatch API to allow the consumer restrictions of specific properties.

Primary LanguageC#Apache License 2.0Apache-2.0

JsonPatch.Restrict

Nuget Nuget GitHub issues GitHub Discord

Provides an option to restrict the properties which are allowed to be modified by a JSON PATCH operation.

Installation

You can either get this package by downloading it from the NuGet Package Manager built in Visual Studio, in the releases tab or from the official nuget.org website.

Also you can install it via the Package Manager Console:

Install-Package JsonPatch.Restrict

Basic example

public class DummyModel
{
    public int Id { get; set; }
    public string Value { get; set; }
}

var patchDocument = new JsonPatchDocument();
patchDocument.Replace("/Value", "newValue");

patchDocument.ApplyToWithRestrictions(dummy, "Value"); // Allows the Patch to only modify the Value property. This argument takes an array.

Disclaimer

Every method has a Try implementation which wraps around the error lambda, which ussually has to be passed. Also do Note this doesn't work for nested objects. If needed let me know in an issue.

Acknowledgements

I also want to mention the JsonPatch.Patchable package, from which this library is heavily insipred. The reason for this package to exist, is due to the fact that JsonPatch.Patachable enforces DDD violations by applying attributes on your domain entities.

Notes

If you feel like something is not working as intended or you are experiencing issues, feel free to create an issue. Also for feature requests just create an issue. For further information feel free to send me a mail to office@twenty-four.dev or message me on Discord 24_minutes#7496.