From b13d3638c2e8d6d24e8225346a2322dd3eae20ac Mon Sep 17 00:00:00 2001 From: Dominic Frei Date: Wed, 20 Jan 2016 19:39:05 -0500 Subject: [PATCH] [F] Alter pointerValue to be a JSONSubscriptType. --- JsonPatchSwift/JPSJsonPatch.swift | 14 ++++++++------ JsonPatchSwift/JPSJsonPointer.swift | 10 +++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/JsonPatchSwift/JPSJsonPatch.swift b/JsonPatchSwift/JPSJsonPatch.swift index 07d12e2..491accf 100644 --- a/JsonPatchSwift/JPSJsonPatch.swift +++ b/JsonPatchSwift/JPSJsonPatch.swift @@ -100,13 +100,15 @@ extension JPSJsonPatch { throw JPSJsonPatchInitialisationError.InvalidPatchFormat(message: "Operation '\(operation)' is invalid.") } + let pointer = try JPSJsonPointer(rawValue: path) + switch JPSOperation.JPSOperationType(rawValue: operation)! { - case .Add: return JPSOperation(type: JPSOperation.JPSOperationType.Add) - case .Remove: return JPSOperation(type: JPSOperation.JPSOperationType.Remove) - case .Replace: return JPSOperation(type: JPSOperation.JPSOperationType.Replace) - case .Move: return JPSOperation(type: JPSOperation.JPSOperationType.Move) - case .Copy: return JPSOperation(type: JPSOperation.JPSOperationType.Copy) - case .Test: return JPSOperation(type: JPSOperation.JPSOperationType.Test) + case .Add: return JPSOperation(type: JPSOperation.JPSOperationType.Add, pointer: pointer) + case .Remove: return JPSOperation(type: JPSOperation.JPSOperationType.Remove, pointer: pointer) + case .Replace: return JPSOperation(type: JPSOperation.JPSOperationType.Replace, pointer: pointer) + case .Move: return JPSOperation(type: JPSOperation.JPSOperationType.Move, pointer: pointer) + case .Copy: return JPSOperation(type: JPSOperation.JPSOperationType.Copy, pointer: pointer) + case .Test: return JPSOperation(type: JPSOperation.JPSOperationType.Test, pointer: pointer) } } diff --git a/JsonPatchSwift/JPSJsonPointer.swift b/JsonPatchSwift/JPSJsonPointer.swift index 0355c80..7f3c6ba 100644 --- a/JsonPatchSwift/JPSJsonPointer.swift +++ b/JsonPatchSwift/JPSJsonPointer.swift @@ -20,7 +20,7 @@ enum JPSJsonPointerError: ErrorType { struct JPSJsonPointer { let rawValue: String - let pointerValue: [String] + let pointerValue: [JSONSubscriptType] } @@ -39,7 +39,7 @@ extension JPSJsonPointer { let pointerValueWithoutFirstDelimiter = Array(rawValue.componentsSeparatedByString("/").dropFirst()) let pointerValueAfterDecodingDelimiter = pointerValueWithoutFirstDelimiter.map { $0.stringByReplacingOccurrencesOfString("~1", withString: "/") } - let pointerValue = pointerValueAfterDecodingDelimiter.map { $0.stringByReplacingOccurrencesOfString("~0", withString: "~") } + let pointerValue: [JSONSubscriptType] = pointerValueAfterDecodingDelimiter.map { $0.stringByReplacingOccurrencesOfString("~0", withString: "~")} self.init(rawValue: rawValue, pointerValue: pointerValue) } @@ -57,10 +57,10 @@ extension JPSJsonPointer { for i in 0..