Skip to content

Commit

Permalink
Add manual key and init for Codable operators (#58)
Browse files Browse the repository at this point in the history
Co-authored-by: Danny Sung <[email protected]>
  • Loading branch information
mbarnach and dannys42 authored Feb 27, 2021
1 parent f58f566 commit 025968b
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Sources/KituraContracts/Contracts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,15 @@ public struct GreaterThan<I: Identifier>: Operation {
private var value: I
private let `operator`: Operator = .greaterThan

private enum CodingKeys: CodingKey {
case value
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
value = try container.decode(I.self, forKey: .value)
}

/// Creates a GreaterThan instance from a given Identifier value
public init(value: I) {
self.value = value
Expand Down Expand Up @@ -1289,6 +1298,15 @@ public struct GreaterThanOrEqual<I: Identifier>: Operation {
private var value: I
private let `operator`: Operator = .greaterThanOrEqual

private enum CodingKeys: CodingKey {
case value
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
value = try container.decode(I.self, forKey: .value)
}

/// Creates a GreaterThanOrEqual instance from a given Identifier value
public init(value: I) {
self.value = value
Expand Down Expand Up @@ -1337,6 +1355,15 @@ public struct LowerThan<I: Identifier>: Operation {
private var value: I
private let `operator`: Operator = .lowerThan

private enum CodingKeys: CodingKey {
case value
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
value = try container.decode(I.self, forKey: .value)
}

/// Creates a LowerThan instance from a given Identifier value
public init(value: I) {
self.value = value
Expand Down Expand Up @@ -1384,6 +1411,15 @@ public struct LowerThanOrEqual<I: Identifier>: Operation {
private var value: I
private let `operator`: Operator = .lowerThanOrEqual

private enum CodingKeys: CodingKey {
case value
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
value = try container.decode(I.self, forKey: .value)
}

/// Creates a LowerThan instance from a given Identifier value
public init(value: I) {
self.value = value
Expand Down Expand Up @@ -1432,6 +1468,17 @@ public struct InclusiveRange<I: Identifier>: Operation {
private var end: I
private let `operator`: Operator = .inclusiveRange

private enum CodingKeys: CodingKey {
case start
case end
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
start = try container.decode(I.self, forKey: .start)
end = try container.decode(I.self, forKey: .end)
}

/// Creates a InclusiveRange instance from given start and end values
public init(start: I, end: I) {
self.start = start
Expand Down Expand Up @@ -1486,6 +1533,17 @@ public struct ExclusiveRange<I: Identifier>: Operation {
private var end: I
private let `operator`: Operator = .exclusiveRange

private enum CodingKeys: CodingKey {
case start
case end
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
start = try container.decode(I.self, forKey: .start)
end = try container.decode(I.self, forKey: .end)
}

/// Creates a ExclusiveRange instance from given start and end values
public init(start: I, end: I) {
self.start = start
Expand Down

0 comments on commit 025968b

Please sign in to comment.