aspnet / JsonPatch

[Archived] JSON PATCH library. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
103 stars 48 forks source link

[JsonPatch] Add test operation support #1

Closed rynowak closed 7 years ago

rynowak commented 9 years ago

From @kirthik on March 20, 2015 9:37

Test operation in code today does not compare anything. Removing the TODO from code. Pasting code snippet for reference.

var conversionResultTuple = PropertyHelpers.ConvertToActualType(
                typeOfFinalPropertyAtPathLocation,
                operation.value);

            // conversion successful
            if (conversionResultTuple.CanBeConverted)
            {
                // COMPARE - TODO
            }
            else
            {
                throw new JsonPatchException<T>(operation,
                    string.Format("Patch failed: provided value is invalid for property type at location path: {0}",
                        operation.path),
                    objectToApplyTo);
            }

Copied from original issue: aspnet/Mvc#2218

rynowak commented 9 years ago

From @danroth27 on April 1, 2015 16:16

@kirthik Do we currently return a 400 level error response if someone tries a test operation?

rynowak commented 9 years ago

From @kirthik on April 1, 2015 17:4

No. We don't. It does nothing today.

Levitikon217 commented 7 years ago

Curious.. Will the Test Operator be implemented at some point? If so, do you know when? I'm requiring functionality that the test operator provides and I'm considering my options here.

zygimantas commented 7 years ago

As a workaround I use:

// JSON.stringify([{ op: "test", path: "/key", value: "key_value"}])
// [FromBody] JsonPatchDocument<CustomRequestModel> jsonPatchDocument

var operation = jsonPatchDocument.Operations.SingleOrDefault(
a => a.OperationType == OperationType.Test &&
a.path.Equals("/key", System.StringComparison.CurrentCultureIgnoreCase));

// (string)operation.value