https://github.com/twentyfourminutes/jsonpatch.restrict
Extends the Microsoft.AspNetCore.JsonPatch API to allow the consumer restrictions of specific properties.
https://github.com/twentyfourminutes/jsonpatch.restrict
aspnetcore extension json json-patch patch restrictions
Last synced: about 2 months ago
JSON representation
Extends the Microsoft.AspNetCore.JsonPatch API to allow the consumer restrictions of specific properties.
- Host: GitHub
- URL: https://github.com/twentyfourminutes/jsonpatch.restrict
- Owner: TwentyFourMinutes
- License: apache-2.0
- Created: 2020-08-11T08:50:26.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-01-29T07:30:30.000Z (over 4 years ago)
- Last Synced: 2025-01-18T05:42:45.895Z (3 months ago)
- Topics: aspnetcore, extension, json, json-patch, patch, restrictions
- Language: C#
- Homepage:
- Size: 29.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# JsonPatch.Restrict
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](https://github.com/TwentyFourMinutes/JsonPatch.Restrict/releases) tab or from the official [nuget.org](https://www.nuget.org/packages/JsonPatch.Restrict) website.
Also you can install it via the **P**ackage **M**anager **C**onsole:
```
Install-Package JsonPatch.Restrict
```### Basic example
```c#
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.
```
### DisclaimerEvery 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`](https://github.com/Labradoratory/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](mailto:[email protected]) to `[email protected]` or message me on Discord `24_minutes#7496`.