// Generated by swift/JSONRender/Scripts/generate-spec-model.mjs. // Do not edit by hand. Change the source declarations in packages/core // (types.ts and actions.ts) and run the script to regenerate this file. import Foundation /// Generated from packages/core (union type). public indirect enum DynamicValue: Codable, Equatable, Sendable { case value(JSONValue) case state(String) public init(from decoder: Decoder) throws { if let container = try? decoder.container(keyedBy: DynamicCodingKey.self) { if container.contains(DynamicCodingKey("$state")) { self = .state(try container.decode(String.self, forKey: DynamicCodingKey("$state"))) return } } let single = try decoder.singleValueContainer() if let value = try? single.decode(JSONValue.self) { self = .value(value) return } throw DecodingError.dataCorruptedError( in: single, debugDescription: "DynamicValue does not match any known shape" ) } public func encode(to encoder: Encoder) throws { switch self { case .value(let value): var container = encoder.singleValueContainer() try container.encode(value) case .state(let value): var container = encoder.container(keyedBy: DynamicCodingKey.self) try container.encode(value, forKey: DynamicCodingKey("$state")) } } } /// Generated from packages/core (union type). public indirect enum RepeatStatePath: Codable, Equatable, Sendable { case string(String) case item(String) public init(from decoder: Decoder) throws { if let container = try? decoder.container(keyedBy: DynamicCodingKey.self) { if container.contains(DynamicCodingKey("$item")) { self = .item(try container.decode(String.self, forKey: DynamicCodingKey("$item"))) return } } let single = try decoder.singleValueContainer() if let value = try? single.decode(String.self) { self = .string(value) return } throw DecodingError.dataCorruptedError( in: single, debugDescription: "RepeatStatePath does not match any known shape" ) } public func encode(to encoder: Encoder) throws { switch self { case .string(let value): var container = encoder.singleValueContainer() try container.encode(value) case .item(let value): var container = encoder.container(keyedBy: DynamicCodingKey.self) try container.encode(value, forKey: DynamicCodingKey("$item")) } } } /// Generated from packages/core (union type). public indirect enum ComparisonValue: Codable, Equatable, Sendable { case number(Double) case state(String) public init(from decoder: Decoder) throws { if let container = try? decoder.container(keyedBy: DynamicCodingKey.self) { if container.contains(DynamicCodingKey("$state")) { self = .state(try container.decode(String.self, forKey: DynamicCodingKey("$state"))) return } } let single = try decoder.singleValueContainer() if let value = try? single.decode(Double.self) { self = .number(value) return } throw DecodingError.dataCorruptedError( in: single, debugDescription: "ComparisonValue does not match any known shape" ) } public func encode(to encoder: Encoder) throws { switch self { case .number(let value): var container = encoder.singleValueContainer() try container.encode(value) case .state(let value): var container = encoder.container(keyedBy: DynamicCodingKey.self) try container.encode(value, forKey: DynamicCodingKey("$state")) } } } /// Generated from packages/core (inline object type). public struct StateCondition: Codable, Equatable, Sendable { public var state: String public var eq: JSONValue? public var neq: JSONValue? public var gt: ComparisonValue? public var gte: ComparisonValue? public var lt: ComparisonValue? public var lte: ComparisonValue? public var not: Bool? public init(state: String, eq: JSONValue? = nil, neq: JSONValue? = nil, gt: ComparisonValue? = nil, gte: ComparisonValue? = nil, lt: ComparisonValue? = nil, lte: ComparisonValue? = nil, not: Bool? = nil) { self.state = state self.eq = eq self.neq = neq self.gt = gt self.gte = gte self.lt = lt self.lte = lte self.not = not } private enum CodingKeys: String, CodingKey { case state = "$state" case eq case neq case gt case gte case lt case lte case not } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.state = try container.decode(String.self, forKey: .state) if container.contains(.eq) { self.eq = try container.decode(JSONValue.self, forKey: .eq) } else { self.eq = nil } if container.contains(.neq) { self.neq = try container.decode(JSONValue.self, forKey: .neq) } else { self.neq = nil } self.gt = try container.decodeIfPresent(ComparisonValue.self, forKey: .gt) self.gte = try container.decodeIfPresent(ComparisonValue.self, forKey: .gte) self.lt = try container.decodeIfPresent(ComparisonValue.self, forKey: .lt) self.lte = try container.decodeIfPresent(ComparisonValue.self, forKey: .lte) self.not = try container.decodeIfPresent(Bool.self, forKey: .not) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(state, forKey: .state) try container.encodeIfPresent(eq, forKey: .eq) try container.encodeIfPresent(neq, forKey: .neq) try container.encodeIfPresent(gt, forKey: .gt) try container.encodeIfPresent(gte, forKey: .gte) try container.encodeIfPresent(lt, forKey: .lt) try container.encodeIfPresent(lte, forKey: .lte) try container.encodeIfPresent(not, forKey: .not) } } /// Generated from packages/core (inline object type). public struct ItemCondition: Codable, Equatable, Sendable { public var item: String public var eq: JSONValue? public var neq: JSONValue? public var gt: ComparisonValue? public var gte: ComparisonValue? public var lt: ComparisonValue? public var lte: ComparisonValue? public var not: Bool? public init(item: String, eq: JSONValue? = nil, neq: JSONValue? = nil, gt: ComparisonValue? = nil, gte: ComparisonValue? = nil, lt: ComparisonValue? = nil, lte: ComparisonValue? = nil, not: Bool? = nil) { self.item = item self.eq = eq self.neq = neq self.gt = gt self.gte = gte self.lt = lt self.lte = lte self.not = not } private enum CodingKeys: String, CodingKey { case item = "$item" case eq case neq case gt case gte case lt case lte case not } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.item = try container.decode(String.self, forKey: .item) if container.contains(.eq) { self.eq = try container.decode(JSONValue.self, forKey: .eq) } else { self.eq = nil } if container.contains(.neq) { self.neq = try container.decode(JSONValue.self, forKey: .neq) } else { self.neq = nil } self.gt = try container.decodeIfPresent(ComparisonValue.self, forKey: .gt) self.gte = try container.decodeIfPresent(ComparisonValue.self, forKey: .gte) self.lt = try container.decodeIfPresent(ComparisonValue.self, forKey: .lt) self.lte = try container.decodeIfPresent(ComparisonValue.self, forKey: .lte) self.not = try container.decodeIfPresent(Bool.self, forKey: .not) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(item, forKey: .item) try container.encodeIfPresent(eq, forKey: .eq) try container.encodeIfPresent(neq, forKey: .neq) try container.encodeIfPresent(gt, forKey: .gt) try container.encodeIfPresent(gte, forKey: .gte) try container.encodeIfPresent(lt, forKey: .lt) try container.encodeIfPresent(lte, forKey: .lte) try container.encodeIfPresent(not, forKey: .not) } } /// Generated from packages/core (inline object type). public struct IndexCondition: Codable, Equatable, Sendable { public var index: Bool public var eq: JSONValue? public var neq: JSONValue? public var gt: ComparisonValue? public var gte: ComparisonValue? public var lt: ComparisonValue? public var lte: ComparisonValue? public var not: Bool? public init(index: Bool, eq: JSONValue? = nil, neq: JSONValue? = nil, gt: ComparisonValue? = nil, gte: ComparisonValue? = nil, lt: ComparisonValue? = nil, lte: ComparisonValue? = nil, not: Bool? = nil) { self.index = index self.eq = eq self.neq = neq self.gt = gt self.gte = gte self.lt = lt self.lte = lte self.not = not } private enum CodingKeys: String, CodingKey { case index = "$index" case eq case neq case gt case gte case lt case lte case not } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.index = try container.decode(Bool.self, forKey: .index) if container.contains(.eq) { self.eq = try container.decode(JSONValue.self, forKey: .eq) } else { self.eq = nil } if container.contains(.neq) { self.neq = try container.decode(JSONValue.self, forKey: .neq) } else { self.neq = nil } self.gt = try container.decodeIfPresent(ComparisonValue.self, forKey: .gt) self.gte = try container.decodeIfPresent(ComparisonValue.self, forKey: .gte) self.lt = try container.decodeIfPresent(ComparisonValue.self, forKey: .lt) self.lte = try container.decodeIfPresent(ComparisonValue.self, forKey: .lte) self.not = try container.decodeIfPresent(Bool.self, forKey: .not) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(index, forKey: .index) try container.encodeIfPresent(eq, forKey: .eq) try container.encodeIfPresent(neq, forKey: .neq) try container.encodeIfPresent(gt, forKey: .gt) try container.encodeIfPresent(gte, forKey: .gte) try container.encodeIfPresent(lt, forKey: .lt) try container.encodeIfPresent(lte, forKey: .lte) try container.encodeIfPresent(not, forKey: .not) } } /// Generated from packages/core (union type). public indirect enum SingleCondition: Codable, Equatable, Sendable { case stateCondition(StateCondition) case itemCondition(ItemCondition) case indexCondition(IndexCondition) public init(from decoder: Decoder) throws { let single = try decoder.singleValueContainer() if let value = try? single.decode(StateCondition.self) { self = .stateCondition(value) return } if let value = try? single.decode(ItemCondition.self) { self = .itemCondition(value) return } if let value = try? single.decode(IndexCondition.self) { self = .indexCondition(value) return } throw DecodingError.dataCorruptedError( in: single, debugDescription: "SingleCondition does not match any known shape" ) } public func encode(to encoder: Encoder) throws { switch self { case .stateCondition(let value): var container = encoder.singleValueContainer() try container.encode(value) case .itemCondition(let value): var container = encoder.singleValueContainer() try container.encode(value) case .indexCondition(let value): var container = encoder.singleValueContainer() try container.encode(value) } } } /// Generated from packages/core (inline object type). public struct AndCondition: Codable, Equatable, Sendable { public var and: [VisibilityCondition] public init(and: [VisibilityCondition]) { self.and = and } private enum CodingKeys: String, CodingKey { case and = "$and" } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.and = try container.decode([VisibilityCondition].self, forKey: .and) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(and, forKey: .and) } } /// Generated from packages/core (inline object type). public struct OrCondition: Codable, Equatable, Sendable { public var or: [VisibilityCondition] public init(or: [VisibilityCondition]) { self.or = or } private enum CodingKeys: String, CodingKey { case or = "$or" } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.or = try container.decode([VisibilityCondition].self, forKey: .or) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(or, forKey: .or) } } /// Generated from packages/core (union type). public indirect enum VisibilityCondition: Codable, Equatable, Sendable { case bool(Bool) case singleCondition(SingleCondition) case array([SingleCondition]) case andCondition(AndCondition) case orCondition(OrCondition) public init(from decoder: Decoder) throws { let single = try decoder.singleValueContainer() if let value = try? single.decode(Bool.self) { self = .bool(value) return } if let value = try? single.decode(SingleCondition.self) { self = .singleCondition(value) return } if let value = try? single.decode([SingleCondition].self) { self = .array(value) return } if let value = try? single.decode(AndCondition.self) { self = .andCondition(value) return } if let value = try? single.decode(OrCondition.self) { self = .orCondition(value) return } throw DecodingError.dataCorruptedError( in: single, debugDescription: "VisibilityCondition does not match any known shape" ) } public func encode(to encoder: Encoder) throws { switch self { case .bool(let value): var container = encoder.singleValueContainer() try container.encode(value) case .singleCondition(let value): var container = encoder.singleValueContainer() try container.encode(value) case .array(let value): var container = encoder.singleValueContainer() try container.encode(value) case .andCondition(let value): var container = encoder.singleValueContainer() try container.encode(value) case .orCondition(let value): var container = encoder.singleValueContainer() try container.encode(value) } } } /// Generated from packages/core (string literal union). public enum ActionConfirmVariant: String, Codable, CaseIterable, Sendable { case `default` = "default" case danger = "danger" } /// Generated from packages/core/src/actions.ts. public struct ActionConfirm: Codable, Equatable, Sendable { public var title: String public var message: String public var confirmLabel: String? public var cancelLabel: String? public var variant: ActionConfirmVariant? public init(title: String, message: String, confirmLabel: String? = nil, cancelLabel: String? = nil, variant: ActionConfirmVariant? = nil) { self.title = title self.message = message self.confirmLabel = confirmLabel self.cancelLabel = cancelLabel self.variant = variant } private enum CodingKeys: String, CodingKey { case title case message case confirmLabel case cancelLabel case variant } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.title = try container.decode(String.self, forKey: .title) self.message = try container.decode(String.self, forKey: .message) self.confirmLabel = try container.decodeIfPresent(String.self, forKey: .confirmLabel) self.cancelLabel = try container.decodeIfPresent(String.self, forKey: .cancelLabel) self.variant = try container.decodeIfPresent(ActionConfirmVariant.self, forKey: .variant) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(title, forKey: .title) try container.encode(message, forKey: .message) try container.encodeIfPresent(confirmLabel, forKey: .confirmLabel) try container.encodeIfPresent(cancelLabel, forKey: .cancelLabel) try container.encodeIfPresent(variant, forKey: .variant) } } /// Generated from packages/core (inline object type). public struct ActionOnSuccessAction: Codable, Equatable, Sendable { public var action: String public var params: [String: DynamicValue]? public init(action: String, params: [String: DynamicValue]? = nil) { self.action = action self.params = params } private enum CodingKeys: String, CodingKey { case action case params } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.action = try container.decode(String.self, forKey: .action) self.params = try container.decodeIfPresent([String: DynamicValue].self, forKey: .params) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(action, forKey: .action) try container.encodeIfPresent(params, forKey: .params) } } /// Generated from packages/core (union type). public indirect enum ActionOnSuccess: Codable, Equatable, Sendable { case navigate(String) case set([String: JSONValue]) case action(ActionOnSuccessAction) public init(from decoder: Decoder) throws { if let container = try? decoder.container(keyedBy: DynamicCodingKey.self) { if container.contains(DynamicCodingKey("navigate")) { self = .navigate(try container.decode(String.self, forKey: DynamicCodingKey("navigate"))) return } if container.contains(DynamicCodingKey("set")) { self = .set(try container.decode([String: JSONValue].self, forKey: DynamicCodingKey("set"))) return } if container.contains(DynamicCodingKey("action")) { self = .action(try ActionOnSuccessAction(from: decoder)) return } } let single = try decoder.singleValueContainer() throw DecodingError.dataCorruptedError( in: single, debugDescription: "ActionOnSuccess does not match any known shape" ) } public func encode(to encoder: Encoder) throws { switch self { case .navigate(let value): var container = encoder.container(keyedBy: DynamicCodingKey.self) try container.encode(value, forKey: DynamicCodingKey("navigate")) case .set(let value): var container = encoder.container(keyedBy: DynamicCodingKey.self) try container.encode(value, forKey: DynamicCodingKey("set")) case .action(let value): try value.encode(to: encoder) } } } /// Generated from packages/core (inline object type). public struct ActionOnErrorAction: Codable, Equatable, Sendable { public var action: String public var params: [String: DynamicValue]? public init(action: String, params: [String: DynamicValue]? = nil) { self.action = action self.params = params } private enum CodingKeys: String, CodingKey { case action case params } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.action = try container.decode(String.self, forKey: .action) self.params = try container.decodeIfPresent([String: DynamicValue].self, forKey: .params) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(action, forKey: .action) try container.encodeIfPresent(params, forKey: .params) } } /// Generated from packages/core (union type). public indirect enum ActionOnError: Codable, Equatable, Sendable { case set([String: JSONValue]) case action(ActionOnErrorAction) public init(from decoder: Decoder) throws { if let container = try? decoder.container(keyedBy: DynamicCodingKey.self) { if container.contains(DynamicCodingKey("set")) { self = .set(try container.decode([String: JSONValue].self, forKey: DynamicCodingKey("set"))) return } if container.contains(DynamicCodingKey("action")) { self = .action(try ActionOnErrorAction(from: decoder)) return } } let single = try decoder.singleValueContainer() throw DecodingError.dataCorruptedError( in: single, debugDescription: "ActionOnError does not match any known shape" ) } public func encode(to encoder: Encoder) throws { switch self { case .set(let value): var container = encoder.container(keyedBy: DynamicCodingKey.self) try container.encode(value, forKey: DynamicCodingKey("set")) case .action(let value): try value.encode(to: encoder) } } } /// Generated from packages/core/src/actions.ts. public struct ActionBinding: Codable, Equatable, Sendable { public var action: String public var params: [String: DynamicValue]? public var confirm: ActionConfirm? public var onSuccess: ActionOnSuccess? public var onError: ActionOnError? public var preventDefault: Bool? public init(action: String, params: [String: DynamicValue]? = nil, confirm: ActionConfirm? = nil, onSuccess: ActionOnSuccess? = nil, onError: ActionOnError? = nil, preventDefault: Bool? = nil) { self.action = action self.params = params self.confirm = confirm self.onSuccess = onSuccess self.onError = onError self.preventDefault = preventDefault } private enum CodingKeys: String, CodingKey { case action case params case confirm case onSuccess case onError case preventDefault } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.action = try container.decode(String.self, forKey: .action) self.params = try container.decodeIfPresent([String: DynamicValue].self, forKey: .params) self.confirm = try container.decodeIfPresent(ActionConfirm.self, forKey: .confirm) self.onSuccess = try container.decodeIfPresent(ActionOnSuccess.self, forKey: .onSuccess) self.onError = try container.decodeIfPresent(ActionOnError.self, forKey: .onError) self.preventDefault = try container.decodeIfPresent(Bool.self, forKey: .preventDefault) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(action, forKey: .action) try container.encodeIfPresent(params, forKey: .params) try container.encodeIfPresent(confirm, forKey: .confirm) try container.encodeIfPresent(onSuccess, forKey: .onSuccess) try container.encodeIfPresent(onError, forKey: .onError) try container.encodeIfPresent(preventDefault, forKey: .preventDefault) } } /// Generated from packages/core (union type). public indirect enum ActionBindingList: Codable, Equatable, Sendable { case actionBinding(ActionBinding) case array([ActionBinding]) public init(from decoder: Decoder) throws { let single = try decoder.singleValueContainer() if let value = try? single.decode(ActionBinding.self) { self = .actionBinding(value) return } if let value = try? single.decode([ActionBinding].self) { self = .array(value) return } throw DecodingError.dataCorruptedError( in: single, debugDescription: "ActionBindingList does not match any known shape" ) } public func encode(to encoder: Encoder) throws { switch self { case .actionBinding(let value): var container = encoder.singleValueContainer() try container.encode(value) case .array(let value): var container = encoder.singleValueContainer() try container.encode(value) } } } /// Generated from packages/core (inline object type). public struct Repeat: Codable, Equatable, Sendable { public var statePath: RepeatStatePath public var key: String? public init(statePath: RepeatStatePath, key: String? = nil) { self.statePath = statePath self.key = key } private enum CodingKeys: String, CodingKey { case statePath case key } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.statePath = try container.decode(RepeatStatePath.self, forKey: .statePath) self.key = try container.decodeIfPresent(String.self, forKey: .key) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(statePath, forKey: .statePath) try container.encodeIfPresent(key, forKey: .key) } } /// Generated from packages/core/src/types.ts. public struct UIElement: Codable, Equatable, Sendable { public var type: String public var props: [String: JSONValue] public var children: [String]? public var slots: [String: [String]]? public var visible: VisibilityCondition? public var on: [String: ActionBindingList]? public var `repeat`: Repeat? public var watch: [String: ActionBindingList]? public init(type: String, props: [String: JSONValue], children: [String]? = nil, slots: [String: [String]]? = nil, visible: VisibilityCondition? = nil, on: [String: ActionBindingList]? = nil, `repeat`: Repeat? = nil, watch: [String: ActionBindingList]? = nil) { self.type = type self.props = props self.children = children self.slots = slots self.visible = visible self.on = on self.`repeat` = `repeat` self.watch = watch } private enum CodingKeys: String, CodingKey { case type case props case children case slots case visible case on case `repeat` = "repeat" case watch } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.type = try container.decode(String.self, forKey: .type) self.props = try container.decodeIfPresent([String: JSONValue].self, forKey: .props) ?? [:] self.children = try container.decodeIfPresent([String].self, forKey: .children) self.slots = try container.decodeIfPresent([String: [String]].self, forKey: .slots) self.visible = try container.decodeIfPresent(VisibilityCondition.self, forKey: .visible) self.on = try container.decodeIfPresent([String: ActionBindingList].self, forKey: .on) self.`repeat` = try container.decodeIfPresent(Repeat.self, forKey: .`repeat`) self.watch = try container.decodeIfPresent([String: ActionBindingList].self, forKey: .watch) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(type, forKey: .type) try container.encode(props, forKey: .props) try container.encodeIfPresent(children, forKey: .children) try container.encodeIfPresent(slots, forKey: .slots) try container.encodeIfPresent(visible, forKey: .visible) try container.encodeIfPresent(on, forKey: .on) try container.encodeIfPresent(`repeat`, forKey: .`repeat`) try container.encodeIfPresent(watch, forKey: .watch) } } /// Generated from packages/core/src/types.ts. public struct Spec: Codable, Equatable, Sendable { public var root: String public var elements: [String: UIElement] public var state: [String: JSONValue]? public init(root: String, elements: [String: UIElement], state: [String: JSONValue]? = nil) { self.root = root self.elements = elements self.state = state } private enum CodingKeys: String, CodingKey { case root case elements case state } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.root = try container.decode(String.self, forKey: .root) self.elements = try container.decode([String: UIElement].self, forKey: .elements) self.state = try container.decodeIfPresent([String: JSONValue].self, forKey: .state) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(root, forKey: .root) try container.encode(elements, forKey: .elements) try container.encodeIfPresent(state, forKey: .state) } } /// Generated from packages/core (string literal union). public enum PatchOp: String, Codable, CaseIterable, Sendable { case add = "add" case remove = "remove" case replace = "replace" case move = "move" case copy = "copy" case test = "test" } /// Generated from packages/core/src/types.ts. public struct JsonPatch: Codable, Equatable, Sendable { public var op: PatchOp public var path: String public var value: JSONValue? public var from: String? public init(op: PatchOp, path: String, value: JSONValue? = nil, from: String? = nil) { self.op = op self.path = path self.value = value self.from = from } private enum CodingKeys: String, CodingKey { case op case path case value case from } public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) self.op = try container.decode(PatchOp.self, forKey: .op) self.path = try container.decode(String.self, forKey: .path) if container.contains(.value) { self.value = try container.decode(JSONValue.self, forKey: .value) } else { self.value = nil } self.from = try container.decodeIfPresent(String.self, forKey: .from) } public func encode(to encoder: Encoder) throws { var container = encoder.container(keyedBy: CodingKeys.self) try container.encode(op, forKey: .op) try container.encode(path, forKey: .path) try container.encodeIfPresent(value, forKey: .value) try container.encodeIfPresent(from, forKey: .from) } }