Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add custom decoder for TypeDecoder #27

Merged
merged 2 commits into from
Jul 5, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions Sources/KituraContracts/Contracts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,12 @@ public struct GreaterThan<I: Identifier>: Operation {
public func getOperator() -> Operator {
return self.`operator`
}

// Custom decoder (Fix for TypeDecoder because it cannot return dummy enum Operator value)
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
value = try values.decode(I.self, forKey: .value)
}
}

/**
Expand Down Expand Up @@ -1231,6 +1237,12 @@ public struct GreaterThanOrEqual<I: Identifier>: Operation {
public func getOperator() -> Operator {
return self.`operator`
}

// Custom decoder (Fix for TypeDecoder because it cannot return dummy enum Operator value)
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
value = try values.decode(I.self, forKey: .value)
}
}

/**
Expand Down Expand Up @@ -1279,6 +1291,12 @@ public struct LowerThan<I: Identifier>: Operation {
public func getOperator() -> Operator {
return self.`operator`
}

// Custom decoder (Fix for TypeDecoder because it cannot return dummy enum Operator value)
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
value = try values.decode(I.self, forKey: .value)
}
}

/**
Expand Down Expand Up @@ -1326,6 +1344,12 @@ public struct LowerThanOrEqual<I: Identifier>: Operation {
public func getOperator() -> Operator {
return self.`operator`
}

// Custom decoder (Fix for TypeDecoder because it cannot return dummy enum Operator value)
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
value = try values.decode(I.self, forKey: .value)
}
}

/**
Expand Down Expand Up @@ -1380,6 +1404,13 @@ public struct InclusiveRange<I: Identifier>: Operation {
public func getOperator() -> Operator {
return self.`operator`
}

// Custom decoder (Fix for TypeDecoder because it cannot return dummy enum Operator value)
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
start = try values.decode(I.self, forKey: .start)
end = try values.decode(I.self, forKey: .end)
}
}

/**
Expand Down Expand Up @@ -1434,6 +1465,13 @@ public struct ExclusiveRange<I: Identifier>: Operation {
public func getOperator() -> Operator {
return self.`operator`
}

// Custom decoder (Fix for TypeDecoder because it cannot return dummy enum Operator value)
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
start = try values.decode(I.self, forKey: .start)
end = try values.decode(I.self, forKey: .end)
}
}

//public protocol Persistable: Codable {
Expand Down