diff --git a/Examples/moltin iOS Example/Models/CustomProduct.swift b/Examples/moltin iOS Example/Models/CustomProduct.swift
index 427ed58..1849dd8 100644
--- a/Examples/moltin iOS Example/Models/CustomProduct.swift
+++ b/Examples/moltin iOS Example/Models/CustomProduct.swift
@@ -12,7 +12,7 @@ class CustomProduct: Product {
var backgroundColor: UIColor?
enum ProductCodingKeys: String, CodingKey {
- case backgroundColor = "background_colour"
+ case backgroundColor = "backgroundColour"
}
required init(from decoder: Decoder) throws {
diff --git a/Examples/moltin iOS Example/Models/ProductCategory.swift b/Examples/moltin iOS Example/Models/ProductCategory.swift
index 6efca38..e7cb31e 100644
--- a/Examples/moltin iOS Example/Models/ProductCategory.swift
+++ b/Examples/moltin iOS Example/Models/ProductCategory.swift
@@ -13,8 +13,8 @@ class ProductCategory: moltin.Category {
var backgroundImage: String?
enum ProductCategoryCodingKeys: String, CodingKey {
- case backgroundColor = "background_colour"
- case backgroundImage = "background_image"
+ case backgroundColor = "backgroundColour"
+ case backgroundImage
}
required init(from decoder: Decoder) throws {
diff --git a/Examples/moltin tvOS Example/CategoriesViewController.swift b/Examples/moltin tvOS Example/CategoriesViewController.swift
index 266f09d..871a4c3 100644
--- a/Examples/moltin tvOS Example/CategoriesViewController.swift
+++ b/Examples/moltin tvOS Example/CategoriesViewController.swift
@@ -58,8 +58,8 @@ class ProductCategory: moltin.Category {
var backgroundImage: String?
enum ProductCategoryCodingKeys: String, CodingKey {
- case backgroundColor = "background_colour"
- case backgroundImage = "background_image"
+ case backgroundColor = "backgroundColour"
+ case backgroundImage
}
required init(from decoder: Decoder) throws {
diff --git a/Sources/SDK/Models/Address.swift b/Sources/SDK/Models/Address.swift
index 9e06337..b9ec1d4 100644
--- a/Sources/SDK/Models/Address.swift
+++ b/Sources/SDK/Models/Address.swift
@@ -36,23 +36,6 @@ open class Address: Codable {
/// The country for this address
public var country: String?
- enum CodingKeys: String, CodingKey {
- case firstName = "first_name"
- case lastName = "last_name"
- case companyName = "company_name"
- case line1 = "line_1"
- case line2 = "line_2"
-
- case id
- case type
- case name
- case instructions
- case city
- case county
- case postcode
- case country
- }
-
/// Create a new address with first name and last name
public init(
withFirstName firstName: String,
diff --git a/Sources/SDK/Models/Cart.swift b/Sources/SDK/Models/Cart.swift
index 3cca785..746308e 100644
--- a/Sources/SDK/Models/Cart.swift
+++ b/Sources/SDK/Models/Cart.swift
@@ -11,10 +11,6 @@ import Foundation
public class CartMeta: Codable {
/// The display price information for this cart
public let displayPrice: DisplayPrices
-
- enum CodingKeys: String, CodingKey {
- case displayPrice = "display_price"
- }
}
/// The display price for a `CartItem`
@@ -31,21 +27,12 @@ public struct CartItemDisplayPrices: Codable {
public let withTax: CartItemDisplayPrice
/// The display price for this cart item without tax
public let withoutTax: CartItemDisplayPrice
-
- enum CodingKeys: String, CodingKey {
- case withTax = "with_tax"
- case withoutTax = "without_tax"
- }
}
/// The meta information for this `CartItem`
public class CartItemMeta: Codable {
/// The display price for this cart item
public let displayPrice: CartItemDisplayPrices
-
- enum CodingKeys: String, CodingKey {
- case displayPrice = "display_price"
- }
}
/// Represents a `Cart` in Moltin
@@ -84,21 +71,6 @@ open class CartItem: Codable {
public let links: [String: String]
/// The meta information for this cart
public let meta: CartItemMeta
-
- enum CodingKeys: String, CodingKey {
- case productId = "product_id"
- case unitPrice = "unit_price"
-
- case id
- case type
- case name
- case description
- case sku
- case quantity
- case value
- case links
- case meta
- }
}
/// Represents various types of cart items
diff --git a/Sources/SDK/Models/Currency.swift b/Sources/SDK/Models/Currency.swift
index a66ea92..750797b 100644
--- a/Sources/SDK/Models/Currency.swift
+++ b/Sources/SDK/Models/Currency.swift
@@ -39,20 +39,4 @@ open class Currency: Codable {
public let links: [String: String]
/// The meta information for this currency
public let meta: CurrencyMeta
-
- enum CodingKeys: String, CodingKey {
- case exchangeRate = "exchange_rate"
- case decimalPoint = "decimal_point"
- case thousandSeparator = "thousand_separator"
- case decimalPlaces = "decimal_places"
-
- case id
- case type
- case code
- case format
- case `default`
- case enabled
- case links
- case meta
- }
}
diff --git a/Sources/SDK/Models/File.swift b/Sources/SDK/Models/File.swift
index abfb54d..97a17d4 100644
--- a/Sources/SDK/Models/File.swift
+++ b/Sources/SDK/Models/File.swift
@@ -43,16 +43,4 @@ open class File: Codable {
public let links: [String: String]
/// The meta information for this file
public let meta: FileMeta
-
- enum CodingKeys: String, CodingKey {
- case id
- case type
- case fileName = "file_name"
- case mimeType = "mime_type"
- case fileSize = "file_size"
- case `public`
- case link
- case links
- case meta
- }
}
diff --git a/Sources/SDK/Models/Flow.swift b/Sources/SDK/Models/Flow.swift
index 3428bb5..63e112f 100644
--- a/Sources/SDK/Models/Flow.swift
+++ b/Sources/SDK/Models/Flow.swift
@@ -47,21 +47,6 @@ open class Field: Codable {
public let relationships: Relationships?
/// The meta information for this Field
public let meta: FieldMeta?
-
- enum CodingKeys: String, CodingKey {
- case fieldType = "field_type"
-
- case id
- case type
- case slug
- case name
- case description
- case required
- case unique
- case enabled
- case relationships
- case meta
- }
}
/// Represents a `Flow` in Moltin
diff --git a/Sources/SDK/Models/Order.swift b/Sources/SDK/Models/Order.swift
index 733e4f2..59a01b4 100644
--- a/Sources/SDK/Models/Order.swift
+++ b/Sources/SDK/Models/Order.swift
@@ -13,11 +13,6 @@ public class OrderMeta: Codable {
public let displayPrice: DisplayPrices
/// The timestamps for an order
public let timestamps: Timestamps
-
- enum CodingKeys: String, CodingKey {
- case displayPrice = "display_price"
- case timestamps
- }
}
/// Represents the relationships for an `Order`
@@ -52,20 +47,6 @@ open class Order: Codable {
public let meta: OrderMeta
/// The relationships for this order
public let relationships: OrderRelationships?
-
- enum CodingKeys: String, CodingKey {
- case id
- case type
- case status
- case payment
- case shipping
- case customer
- case shippingAddress = "shipping_address"
- case billingAddress = "billing_address"
- case links
- case meta
- case relationships
- }
}
/// Denotes a successful order returned from the payment gateway
diff --git a/Sources/SDK/Models/Prices.swift b/Sources/SDK/Models/Prices.swift
index b6fcda9..da7d836 100644
--- a/Sources/SDK/Models/Prices.swift
+++ b/Sources/SDK/Models/Prices.swift
@@ -23,9 +23,4 @@ public struct DisplayPrices: Codable {
public let withTax: DisplayPrice
/// The display price without tax
public let withoutTax: DisplayPrice
-
- enum CodingKeys: String, CodingKey {
- case withTax = "with_tax"
- case withoutTax = "without_tax"
- }
}
diff --git a/Sources/SDK/Models/Product.swift b/Sources/SDK/Models/Product.swift
index 5ca2c5d..6566320 100644
--- a/Sources/SDK/Models/Product.swift
+++ b/Sources/SDK/Models/Product.swift
@@ -15,13 +15,6 @@ public struct ProductPrice: Codable {
public let currency: String
/// Whether this price includes tax
public let includesTax: Bool
-
- enum CodingKeys: String, CodingKey {
- case includesTax = "includes_tax"
-
- case amount
- case currency
- }
}
/// Represents stock levels on a `Product`
@@ -62,15 +55,6 @@ public class ProductMeta: Codable {
public let variations: [ProductVariation]?
/// The variation matrix of this product
public let variationMatrix: [[String: String]]?
-
- enum CodingKeys: String, CodingKey {
- case displayPrice = "display_price"
- case variationMatrix = "variation_matrix"
-
- case timestamps
- case stock
- case variations
- }
}
/// Represents a `Product` in moltin
@@ -111,22 +95,6 @@ open class Product: Codable, HasRelationship {
/// The collections this product belongs to
public var collections: [Collection]?
- enum CodingKeys: String, CodingKey {
- case manageStock = "manage_stock"
- case commodityType = "commodity_type"
-
- case id
- case type
- case name
- case slug
- case sku
- case description
- case price
- case status
- case meta
- case relationships
- }
-
required public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let includes: IncludesContainer = decoder.userInfo[.includes] as? IncludesContainer ?? [:]
diff --git a/Sources/SDK/Models/Relationship.swift b/Sources/SDK/Models/Relationship.swift
index 54c7286..3410775 100644
--- a/Sources/SDK/Models/Relationship.swift
+++ b/Sources/SDK/Models/Relationship.swift
@@ -82,18 +82,4 @@ open class Relationships: Codable {
public var cartItem: RelationshipSingle?
/// The `Product` relationships
public var products: RelationshipMany?
-
- enum CodingKeys: String, CodingKey {
- case mainImage = "main_image"
- case cartItem = "cart_item"
-
- case files
- case categories
- case collections
- case brands
- case flow
- case items
- case customer
- case products
- }
}
diff --git a/Sources/SDK/Models/Timestamps.swift b/Sources/SDK/Models/Timestamps.swift
index aec914d..a5c22c0 100644
--- a/Sources/SDK/Models/Timestamps.swift
+++ b/Sources/SDK/Models/Timestamps.swift
@@ -13,9 +13,4 @@ open class Timestamps: Codable {
public let createdAt: Date
/// When the resource was updated
public let updatedAt: Date?
-
- enum CodingKeys: String, CodingKey {
- case createdAt = "created_at"
- case updatedAt = "updated_at"
- }
}
diff --git a/Sources/SDK/Requests/MoltinRequest.swift b/Sources/SDK/Requests/MoltinRequest.swift
index 12b45cd..911ab03 100644
--- a/Sources/SDK/Requests/MoltinRequest.swift
+++ b/Sources/SDK/Requests/MoltinRequest.swift
@@ -52,9 +52,12 @@ public class MoltinRequest {
public init(withConfiguration configuration: MoltinConfig) {
self.config = configuration
self.http = MoltinHTTP(withSession: URLSession.shared)
- self.parser = MoltinParser(withDecoder: JSONDecoder.dateFormattingDecoder())
self.query = MoltinQuery()
self.auth = MoltinAuth(withConfiguration: self.config)
+
+ let encoder = JSONDecoder.dateFormattingDecoder()
+ encoder.keyDecodingStrategy = .convertFromSnakeCase
+ self.parser = MoltinParser(withDecoder: encoder)
}
// MARK: - Default Calls
diff --git a/Sources/SDK/Utils/CodableExtract.swift b/Sources/SDK/Utils/CodableExtract.swift
index 6d9765b..ad43255 100644
--- a/Sources/SDK/Utils/CodableExtract.swift
+++ b/Sources/SDK/Utils/CodableExtract.swift
@@ -48,6 +48,7 @@ extension Decodable {
let itemData = try JSONSerialization.data(withJSONObject: item, options: [])
let decoder = JSONDecoder.dateFormattingDecoder()
+ decoder.keyDecodingStrategy = .convertFromSnakeCase
return try decoder.decode(T.self, from: itemData)
}
@@ -59,6 +60,7 @@ extension Decodable {
let itemData = try JSONSerialization.data(withJSONObject: items, options: [])
let decoder = JSONDecoder.dateFormattingDecoder()
+ decoder.keyDecodingStrategy = .convertFromSnakeCase
return try decoder.decode([T].self, from: itemData)
}
diff --git a/Tests/moltin iOS Tests/AuthTests.swift b/Tests/moltin iOS Tests/AuthTests.swift
index fb77d13..9de93c4 100644
--- a/Tests/moltin iOS Tests/AuthTests.swift
+++ b/Tests/moltin iOS Tests/AuthTests.swift
@@ -42,9 +42,9 @@ class AuthRequestTests: XCTestCase {
func testAuthAuthenticatesSuccessfullyAndPassesThrough() {
let (_, productRequest) = MockFactory.mockedProductRequest(withJSON: MockProductDataFactory.multiProductData)
-
+
let expectationToFulfill = expectation(description: "ProductRequest calls the method and runs the callback closure")
-
+
_ = productRequest.all { (result) in
switch result {
case .success(_):
@@ -58,10 +58,10 @@ class AuthRequestTests: XCTestCase {
}
break
}
-
+
expectationToFulfill.fulfill()
}
-
+
waitForExpectations(timeout: 1) { error in
if let error = error {
XCTFail("waitForExpectationsWithTimeout errored: \(error)")
diff --git a/moltin.xcodeproj/xcshareddata/xcschemes/moltin iOS Example.xcscheme b/moltin.xcodeproj/xcshareddata/xcschemes/moltin iOS Example.xcscheme
new file mode 100644
index 0000000..dd2c854
--- /dev/null
+++ b/moltin.xcodeproj/xcshareddata/xcschemes/moltin iOS Example.xcscheme
@@ -0,0 +1,91 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/moltin.xcodeproj/xcuserdata/craigtweedy.xcuserdatad/xcschemes/xcschememanagement.plist b/moltin.xcodeproj/xcuserdata/craigtweedy.xcuserdatad/xcschemes/xcschememanagement.plist
index 93eccfd..fe320be 100644
--- a/moltin.xcodeproj/xcuserdata/craigtweedy.xcuserdatad/xcschemes/xcschememanagement.plist
+++ b/moltin.xcodeproj/xcuserdata/craigtweedy.xcuserdatad/xcschemes/xcschememanagement.plist
@@ -9,11 +9,21 @@
orderHint
5
+ moltin WatchKit Example.xcscheme_^#shared#^_
+
+ orderHint
+ 5
+
moltin iOS Example.xcscheme
orderHint
4
+ moltin iOS Example.xcscheme_^#shared#^_
+
+ orderHint
+ 4
+
moltin iOS Tests.xcscheme
orderHint
@@ -29,6 +39,11 @@
orderHint
6
+ moltin tvOS Example.xcscheme_^#shared#^_
+
+ orderHint
+ 6
+
moltin tvOS Tests.xcscheme
orderHint