Skip to content

Commit

Permalink
Switch from Codable to Encodable for JSON protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Jan 11, 2025
1 parent ada81cd commit 4bc14f0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Sources/WalletOrders/OrderJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ public enum OrderJSON {
/// A protocol that defines the structure of a `order.json` file.
///
/// > Tip: See the [`Order`](https://developer.apple.com/documentation/walletorders/order) object to understand the keys.
public protocol Properties: Codable, Sendable {
public protocol Properties: Encodable, Sendable {
/// The date and time when the customer created the order, in RFC 3339 format.
var createdAt: String { get }

Expand Down Expand Up @@ -48,7 +48,7 @@ extension OrderJSON {
/// A protocol that represents the merchant associated with the order.
///
/// > Tip: See the [`Order.Merchant`](https://developer.apple.com/documentation/walletorders/merchant) object to understand the keys.
public protocol Merchant: Codable, Sendable {
public protocol Merchant: Encodable, Sendable {
/// The localized display name of the merchant.
var displayName: String { get }

Expand All @@ -64,7 +64,7 @@ extension OrderJSON {
/// A protocol that represents the details of a barcode for an order.
///
/// > Tip: See the [`Order.Barcode`](https://developer.apple.com/documentation/walletorders/barcode) object to understand the keys.
public protocol Barcode: Codable, Sendable {
public protocol Barcode: Encodable, Sendable {
/// The format of the barcode.
var format: BarcodeFormat { get }

Expand Down
12 changes: 6 additions & 6 deletions Sources/WalletPasses/PassJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ public enum PassJSON {
/// A protocol that defines the structure of a `pass.json` file.
///
/// > Tip: See the [`Pass`](https://developer.apple.com/documentation/walletpasses/pass) object to understand the keys.
public protocol Properties: Codable, Sendable {
public protocol Properties: Encodable, Sendable {
/// A short description that iOS accessibility technologies use for a pass.
var description: String { get }

Expand Down Expand Up @@ -34,7 +34,7 @@ extension PassJSON {
/// A protocol that represents the information to display in a field on a pass.
///
/// > Tip: See the [`PassFieldContent`](https://developer.apple.com/documentation/walletpasses/passfieldcontent) object to understand the keys.
public protocol PassFieldContent: Codable, Sendable {
public protocol PassFieldContent: Encodable, Sendable {
/// A unique key that identifies a field in the pass; for example, `departure-gate`.
var key: String { get }

Expand All @@ -49,7 +49,7 @@ extension PassJSON {
/// A protocol that represents the groups of fields that display the information for a boarding pass.
///
/// > Tip: See the [`Pass.BoardingPass`](https://developer.apple.com/documentation/walletpasses/pass/boardingpass) object to understand the keys.
public protocol BoardingPass: Codable, Sendable {
public protocol BoardingPass: Encodable, Sendable {
/// The type of transit for a boarding pass.
///
/// This key is invalid for other types of passes.
Expand All @@ -64,7 +64,7 @@ extension PassJSON {
/// A protocol that represents a barcode on a pass.
///
/// > Tip: See the [`Pass.Barcodes`](https://developer.apple.com/documentation/walletpasses/pass/barcodes) object to understand the keys.
public protocol Barcodes: Codable, Sendable {
public protocol Barcodes: Encodable, Sendable {
/// The format of the barcode.
///
/// The barcode format `PKBarcodeFormatCode128` isn’t supported for watchOS.
Expand All @@ -83,7 +83,7 @@ extension PassJSON {
/// A protocol that represents a location that the system uses to show a relevant pass.
///
/// > Tip: See the [`Pass.Locations`](https://developer.apple.com/documentation/walletpasses/pass/locations) object to understand the keys.
public protocol Locations: Codable, Sendable {
public protocol Locations: Encodable, Sendable {
/// The latitude, in degrees, of the location.
var latitude: Double { get }

Expand All @@ -96,7 +96,7 @@ extension PassJSON {
/// An object that represents the near-field communication (NFC) payload the device passes to an Apple Pay terminal.
///
/// > Tip: See the [`Pass.NFC`](https://developer.apple.com/documentation/walletpasses/pass/nfc) object to understand the keys.
public protocol NFC: Codable, Sendable {
public protocol NFC: Encodable, Sendable {
/// The payload the device transmits to the Apple Pay terminal.
///
/// The size must be no more than 64 bytes.
Expand Down
4 changes: 2 additions & 2 deletions Tests/WalletOrdersTests/TestOrder.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import WalletOrders

struct TestOrder: OrderJSON.Properties {
struct TestOrder: OrderJSON.Properties, Decodable {
var schemaVersion = OrderJSON.SchemaVersion.v1
var orderTypeIdentifier = "order.com.example.swift-wallet"
var orderIdentifier = UUID().uuidString
Expand All @@ -15,7 +15,7 @@ struct TestOrder: OrderJSON.Properties {
var authenticationToken = UUID().uuidString
var webServiceURL = "https://www.example.com/api/orders/"

struct MerchantData: OrderJSON.Merchant {
struct MerchantData: OrderJSON.Merchant, Decodable {
var merchantIdentifier = "com.example.pet-store"
var displayName = "Pet Store"
var url = "https://www.example.com/"
Expand Down
10 changes: 5 additions & 5 deletions Tests/WalletPassesTests/TestPass.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import WalletPasses

struct TestPass: PassJSON.Properties {
struct TestPass: PassJSON.Properties, Decodable {
var description = "Test Pass"
var formatVersion = PassJSON.FormatVersion.v1
var organizationName = "example"
Expand All @@ -15,23 +15,23 @@ struct TestPass: PassJSON.Properties {
var backgroundColor = "rgb(207, 77, 243)"
var foregroundColor = "rgb(255, 255, 255)"

var barcodes = Barcode(message: "test")
struct Barcode: PassJSON.Barcodes {
var barcodes = [Barcode(message: "test")]
struct Barcode: PassJSON.Barcodes, Decodable {
var format = PassJSON.BarcodeFormat.qr
var message: String
var messageEncoding = "iso-8859-1"
}

var boardingPass = Boarding(transitType: .air)
struct Boarding: PassJSON.BoardingPass {
struct Boarding: PassJSON.BoardingPass, Decodable {
let transitType: PassJSON.TransitType
let headerFields: [PassField]
let primaryFields: [PassField]
let secondaryFields: [PassField]
let auxiliaryFields: [PassField]
let backFields: [PassField]

struct PassField: PassJSON.PassFieldContent {
struct PassField: PassJSON.PassFieldContent, Decodable {
let key: String
let label: String
let value: String
Expand Down

0 comments on commit 4bc14f0

Please sign in to comment.