passes 1.0.1

Rust library for generate Apple Wallet Passes for iOS, WatchOS, MacOS.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
use chrono::{DateTime, Utc};
use is_empty::IsEmpty;
use serde::{Deserialize, Serialize};

use self::barcode::Barcode;
use self::beacon::Beacon;
use self::location::Location;
use self::nfc::NFC;
use self::semantic_tags::SemanticTags;
use self::visual_appearance::VisualAppearance;
use self::web_service::WebService;

pub mod barcode;
pub mod beacon;
mod date_format;
pub mod fields;
pub mod location;
pub mod nfc;
pub mod semantic_tags;
pub mod visual_appearance;
pub mod web_service;

/// Required fields for [Pass]
///
/// Used for [Pass] construction
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct PassConfig {
    /// The name of the organization.
    pub organization_name: String,

    /// A short description that iOS accessibility technologies use for a pass.
    pub description: String,

    /// The pass type identifier that’s registered with Apple.
    /// The value must be the same as the distribution certificate used to sign the pass.
    pub pass_type_identifier: String,

    /// The Team ID for the Apple Developer Program account that registered the pass type identifier.
    pub team_identifier: String,

    /// An alphanumeric serial number.
    /// The combination of the serial number and pass type identifier must be unique for each pass.
    pub serial_number: String,
}

/// Represents a pass (pass.json file)
///
/// Example for making [Pass] with [PassConfig]:
///
/// ```
/// use passes::{PassBuilder, PassConfig};
/// let pass = PassBuilder::new(PassConfig {
///     organization_name: String::from("Apple inc."),
///     description: String::from("Example pass"),
///     pass_type_identifier: String::from("com.example.pass"),
///     team_identifier: String::from("AA00AA0A0A"),
///     serial_number: String::from("ABCDEFG1234567890"),
/// })
/// .build();
/// ```
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Pass {
    /// The version of the file format. The value must be 1.
    format_version: u32,

    /// Primary required fields, specified for pass.json
    #[serde(flatten)]
    pub config: PassConfig,

    /// An identifier the system uses to group related boarding passes or event tickets.
    ///
    /// Wallet displays passes with the same [grouping_identifier](Pass::grouping_identifier), [pass_type_identifier](PassConfig::pass_type_identifier), and type as a group.
    ///
    /// Use this identifier to group passes that are tightly related, such as boarding passes for different connections on the same trip.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub grouping_identifier: Option<String>,

    /// Colors and other visual parts of the pass
    #[serde(default)]
    #[serde(flatten)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub appearance: Option<VisualAppearance>,

    /// The text to display next to the logo on the pass.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub logo_text: Option<String>,

    /// The date and time when the pass becomes relevant
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(with = "date_format")]
    pub relevant_date: Option<DateTime<Utc>>,

    /// The date and time the pass expires.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(with = "date_format")]
    pub expiration_date: Option<DateTime<Utc>>,

    /// A URL to be passed to the associated app when launching it.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(rename = "appLaunchURL")]
    pub app_launch_url: Option<String>,

    /// An array of App Store identifiers for apps associated with the pass.
    #[serde(default)]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub associated_store_identifiers: Vec<i32>,

    /// Implement a web server to register, update, and unregister a pass on a device.
    ///
    /// See [Apple documentation](https://developer.apple.com/documentation/walletpasses/adding_a_web_service_to_update_passes)
    #[serde(default)]
    #[serde(flatten)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub web_service: Option<WebService>,

    /// Controls whether to show the Share button on the back of a pass.
    ///
    /// A value of true removes the button. The default value is false.
    ///
    /// This flag has no effect in earlier versions of iOS, nor does it prevent sharing the pass in some other way.
    #[serde(default)]
    #[serde(skip_serializing_if = "_is_false")]
    pub sharing_prohibited: bool,

    /// Controls whether to display the strip image without a shine effect.
    ///
    /// The default value is true.
    #[serde(default = "_default_true")]
    #[serde(skip_serializing_if = "_is_true")]
    pub suppress_strip_shine: bool,

    /// Indicates that the pass is void, such as a redeemed, one-time-use coupon.
    ///
    /// The default value is false.
    #[serde(default)]
    #[serde(skip_serializing_if = "_is_false")]
    pub voided: bool,

    /// Barcode on a pass
    ///
    /// The system uses the first displayable barcode for the device.
    #[serde(default)]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub barcodes: Vec<Barcode>,

    // Array of Bluetooth Low Energy beacons the system uses to show a relevant pass.
    #[serde(default)]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub beacons: Vec<Beacon>,

    // An array of up to 10 geographic locations the system uses to show a relevant pass.
    #[serde(default)]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub locations: Vec<Location>,

    /// The maximum distance, in meters, from a location in the [locations](Pass::locations) array at which the pass is relevant.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_distance: Option<u32>,

    /// Near-field communication (NFC) payload the device passes to an Apple Pay terminal.
    #[serde(default)]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nfc: Option<NFC>,

    /// Semantic tags
    ///
    /// Metadata the system uses to offer a pass and suggest related actions.
    /// For example, setting Don’t Disturb mode for the duration of a movie.
    #[serde(default)]
    #[serde(skip_serializing_if = "SemanticTags::is_empty")]
    pub semantics: SemanticTags,

    /// Groups of visible fields that display information on the front and back of a pass.
    #[serde(flatten)]
    pub fields: fields::Type,
    // TODO: UserInfo
    // custom JSON
}

impl Pass {
    /// Build JSON output for pass (pass.json)
    ///
    /// ```
    /// use passes::{PassConfig, PassBuilder};
    ///
    /// let pass = PassBuilder::new(PassConfig {
    ///     organization_name: String::from("Apple inc."),
    ///     description: String::from("Example pass"),
    ///     pass_type_identifier: String::from("com.example.pass"),
    ///     team_identifier: String::from("AA00AA0A0A"),
    ///     serial_number: String::from("ABCDEFG1234567890"),
    /// })
    /// .build();
    ///
    /// let json = pass.make_json().unwrap();
    ///
    /// let json_expected = r#"{
    ///   "formatVersion": 1,
    ///   "organizationName": "Apple inc.",
    ///   "description": "Example pass",
    ///   "passTypeIdentifier": "com.example.pass",
    ///   "teamIdentifier": "AA00AA0A0A",
    ///   "serialNumber": "ABCDEFG1234567890",
    ///   "generic": {
    ///     "auxiliaryFields": [],
    ///     "backFields": [],
    ///     "headerFields": [],
    ///     "primaryFields": [],
    ///     "secondaryFields": []
    ///   }
    /// }"#;
    ///
    /// assert_eq!(json_expected, json);
    /// ```
    pub fn make_json(&self) -> Result<String, serde_json::Error> {
        let json = serde_json::to_string_pretty(&self)?;
        Ok(json)
    }

    /// Build pass (pass.json) from json data
    ///
    /// ```
    /// use passes::Pass;
    ///
    /// let json_expected = r#"{
    ///   "formatVersion": 1,
    ///   "organizationName": "Apple inc.",
    ///   "description": "Example pass",
    ///   "passTypeIdentifier": "com.example.pass",
    ///   "teamIdentifier": "AA00AA0A0A",
    ///   "serialNumber": "ABCDEFG1234567890",
    ///   "generic": {
    ///     "auxiliaryFields": [],
    ///     "backFields": [],
    ///     "headerFields": [],
    ///     "primaryFields": [],
    ///     "secondaryFields": []
    ///   }
    /// }"#;
    ///
    /// let pass: Pass = Pass::from_json(json_expected).unwrap();
    /// let json = pass.make_json().unwrap();
    /// assert_eq!(json_expected, json);
    /// ```
    pub fn from_json(data: &str) -> Result<Self, serde_json::Error> {
        let pass: Pass = serde_json::from_str(data)?;
        Ok(pass)
    }
}

/// Builder for pass (represents pass.json file)
pub struct PassBuilder {
    pass: Pass,
}

impl PassBuilder {
    /// Creates builder for `Pass`.
    pub fn new(config: PassConfig) -> Self {
        let pass = Pass {
            // setup required vars
            format_version: 1,
            config,
            // Setup default optional vars
            grouping_identifier: None,
            appearance: None,
            logo_text: None,
            relevant_date: None,
            expiration_date: None,
            app_launch_url: None,
            associated_store_identifiers: Vec::new(),
            web_service: None,
            sharing_prohibited: false,
            suppress_strip_shine: true,
            voided: false,
            barcodes: Vec::new(),
            beacons: Vec::new(),
            locations: Vec::new(),
            max_distance: None,
            nfc: None,
            semantics: Default::default(),
            fields: fields::Type::Generic {
                pass_fields: fields::Fields {
                    ..Default::default()
                },
            },
        };
        Self { pass }
    }

    /// Adding [grouping_identifier](Pass::grouping_identifier)
    pub fn grouping_identifier(mut self, field: String) -> PassBuilder {
        self.pass.grouping_identifier = Some(field);
        self
    }

    /// Adding [appearance](Pass::appearance).
    pub fn appearance(mut self, field: VisualAppearance) -> PassBuilder {
        self.pass.appearance = Some(field);
        self
    }

    /// Adding [logo_text](Pass::logo_text)
    pub fn logo_text(mut self, field: String) -> PassBuilder {
        self.pass.logo_text = Some(field);
        self
    }

    /// Adding [relevant_date](Pass::relevant_date)
    ///
    /// ```
    /// use chrono::prelude::*;
    /// use passes::{PassBuilder, PassConfig};
    ///
    /// let pass = PassBuilder::new(PassConfig {
    ///     organization_name: String::from("Apple inc."),
    ///     description: String::from("Example pass"),
    ///     pass_type_identifier: String::from("com.example.pass"),
    ///     team_identifier: String::from("AA00AA0A0A"),
    ///     serial_number: String::from("ABCDEFG1234567890"),
    /// }).relevant_date(Utc.with_ymd_and_hms(2024, 02, 07, 0, 0, 0).unwrap());
    /// ```
    pub fn relevant_date(mut self, field: DateTime<Utc>) -> PassBuilder {
        self.pass.relevant_date = Some(field);
        self
    }

    /// Adding [expiration_date](Pass::expiration_date)
    pub fn expiration_date(mut self, field: DateTime<Utc>) -> PassBuilder {
        self.pass.expiration_date = Some(field);
        self
    }

    /// Adding [app_launch_url](Pass::app_launch_url)
    pub fn app_launch_url(mut self, field: String) -> PassBuilder {
        self.pass.app_launch_url = Some(field);
        self
    }

    /// Adding [associated_store_identifiers](Pass::associated_store_identifiers)
    pub fn add_associated_store_identifier(mut self, id: i32) -> PassBuilder {
        self.pass.associated_store_identifiers.push(id);
        self
    }

    /// Adding [web_service_url](WebService::web_service_url)
    pub fn web_service(mut self, web_service: WebService) -> PassBuilder {
        self.pass.web_service = Some(web_service);
        self
    }

    /// Adding [sharing_prohibited](Pass::sharing_prohibited)
    pub fn set_sharing_prohibited(mut self, field: bool) -> PassBuilder {
        self.pass.sharing_prohibited = field;
        self
    }

    /// Adding [suppress_strip_shine](Pass::suppress_strip_shine)
    pub fn set_suppress_strip_shine(mut self, field: bool) -> PassBuilder {
        self.pass.suppress_strip_shine = field;
        self
    }

    /// Adding [voided](Pass::voided)
    pub fn voided(mut self, field: bool) -> PassBuilder {
        self.pass.voided = field;
        self
    }

    /// Adding [Barcode] to [barcodes](Pass::barcodes)
    pub fn add_barcode(mut self, barcode: Barcode) -> PassBuilder {
        self.pass.barcodes.push(barcode);
        self
    }

    /// Adding [Beacon] to [beacons](Pass::beacons)
    pub fn add_beacon(mut self, beacon: Beacon) -> PassBuilder {
        self.pass.beacons.push(beacon);
        self
    }

    /// Adding [Location] to [locations](Pass::locations)
    pub fn add_location(mut self, location: Location) -> PassBuilder {
        assert!(
            self.pass.locations.len() < 10,
            "Reached limit for geographic locations (maximum - 10)"
        );
        self.pass.locations.push(location);
        self
    }

    /// Adding [max_distance](Pass::max_distance)
    pub fn max_distance(mut self, field: u32) -> PassBuilder {
        self.pass.max_distance = Some(field);
        self
    }

    /// Adding [nfc](Pass::nfc)
    pub fn nfc(mut self, field: NFC) -> PassBuilder {
        self.pass.nfc = Some(field);
        self
    }

    /// Adding [semantics](Pass::semantics)
    ///
    /// ```
    /// use passes::{PassBuilder, PassConfig, semantic_tags};
    ///
    /// let pass = PassBuilder::new(PassConfig {
    ///     organization_name: String::from("Apple inc."),
    ///     description: String::from("Example pass"),
    ///     pass_type_identifier: String::from("com.example.pass"),
    ///     team_identifier: String::from("AA00AA0A0A"),
    ///     serial_number: String::from("ABCDEFG1234567890"),
    /// }).semantics(semantic_tags::SemanticTags {
    ///     airline_code: String::from("EX123").into(),
    ///     departure_location: semantic_tags::SemanticTagLocation {
    ///         latitude: 43.3948533,
    ///         longitude: 132.1451673,
    ///     }
    ///     .into(),
    ///     ..Default::default()
    /// });
    /// ```
    pub fn semantics(mut self, field: SemanticTags) -> PassBuilder {
        self.pass.semantics = field;
        self
    }

    /// Adding [fields](Pass::fields)
    ///
    /// ```
    /// use passes::{PassBuilder, PassConfig, fields};
    ///
    /// let pass = PassBuilder::new(PassConfig {
    ///     organization_name: String::from("Apple inc."),
    ///     description: String::from("Example pass"),
    ///     pass_type_identifier: String::from("com.example.pass"),
    ///     team_identifier: String::from("AA00AA0A0A"),
    ///     serial_number: String::from("ABCDEFG1234567890"),
    /// }).fields(
    ///     fields::Type::BoardingPass {
    ///         pass_fields: fields::Fields {
    ///             ..Default::default()
    ///         },
    ///         transit_type: fields::TransitType::Air,
    ///     }
    ///     .add_header_field(fields::Content::new(
    ///         "serial",
    ///         "1122",
    ///         fields::ContentOptions {
    ///             label: String::from("SERIAL").into(),
    ///             ..Default::default()
    ///         },
    ///     ))
    ///     .add_primary_field(fields::Content::new(
    ///     "from",
    ///     "RKSI",
    ///     fields::ContentOptions {
    ///         label: String::from("FROM").into(),
    ///         text_alignment: fields::TextAlignment::Right.into(),
    ///         ..Default::default()
    ///     },
    /// )));
    /// ```
    pub fn fields(mut self, field: fields::Type) -> PassBuilder {
        self.pass.fields = field;
        self
    }

    /// Makes `Pass`.
    pub fn build(self) -> Pass {
        self.pass
    }
}

#[cfg(test)]
mod tests {
    use chrono::prelude::*;
    use tests::{fields, semantic_tags::SemanticTagLocation, visual_appearance::Color};

    use super::*;

    #[test]
    fn make_minimal_pass() {
        // Serialization test
        let pass = PassBuilder::new(PassConfig {
            organization_name: String::from("Apple inc."),
            description: String::from("Example pass"),
            pass_type_identifier: String::from("com.example.pass"),
            team_identifier: String::from("AA00AA0A0A"),
            serial_number: String::from("ABCDEFG1234567890"),
        })
        .build();

        let json = pass.make_json().unwrap();

        println!("{}", json);

        let json_expected = r#"{
  "formatVersion": 1,
  "organizationName": "Apple inc.",
  "description": "Example pass",
  "passTypeIdentifier": "com.example.pass",
  "teamIdentifier": "AA00AA0A0A",
  "serialNumber": "ABCDEFG1234567890",
  "generic": {
    "auxiliaryFields": [],
    "backFields": [],
    "headerFields": [],
    "primaryFields": [],
    "secondaryFields": []
  }
}"#;

        assert_eq!(json_expected, json);

        // Deserialization test
        let pass: Pass = Pass::from_json(json_expected).unwrap();
        let json = pass.make_json().unwrap();
        assert_eq!(json_expected, json);
    }

    #[test]
    fn make_pass() {
        // Serialization test
        let pass = PassBuilder::new(PassConfig {
            organization_name: String::from("Apple inc."),
            description: String::from("Example pass"),
            pass_type_identifier: String::from("com.example.pass"),
            team_identifier: String::from("AA00AA0A0A"),
            serial_number: String::from("ABCDEFG1234567890"),
        })
        .grouping_identifier(String::from("com.example.pass.app"))
        .appearance(VisualAppearance {
            label_color: None,
            foreground_color: Color::new(250, 10, 10),
            background_color: Color::white(),
        })
        .logo_text(String::from("Test pass"))
        .relevant_date(Utc.with_ymd_and_hms(2024, 02, 07, 0, 0, 0).unwrap())
        .expiration_date(Utc.with_ymd_and_hms(2024, 02, 08, 0, 0, 0).unwrap())
        .app_launch_url(String::from("testapp:param?index=1"))
        .add_associated_store_identifier(100)
        .web_service(WebService {
            authentication_token: String::from("abcdefg01234567890abcdefg"),
            web_service_url: String::from("https://example.com/passes/"),
        })
        .set_sharing_prohibited(false)
        .set_suppress_strip_shine(false)
        .voided(false)
        .add_barcode(Barcode {
            message: String::from("Hello world!"),
            format: barcode::BarcodeFormat::QR,
            alt_text: Some(String::from("test by test")),
            ..Default::default()
        })
        .add_beacon(Beacon {
            proximity_uuid: String::from("e286373b-15b5-4f4e-bf91-e9e64787724a"),
            major: Some(2),
            minor: Some(150),
            relevant_text: Some(String::from("The simple beacon")),
        })
        .add_location(Location {
            latitude: 37.334606,
            longitude: -122.009102,
            relevant_text: Some(String::from("Apple Park, Cupertino, CA, USA")),
            ..Default::default()
        })
        .max_distance(1000)
        .nfc(NFC {
            encryption_public_key: String::from("ABCDEFG_0011223344556677889900"),
            message: String::from("test message"),
            ..Default::default()
        })
        .semantics(SemanticTags {
            airline_code: String::from("EX123").into(),
            departure_location: SemanticTagLocation {
                latitude: 43.3948533,
                longitude: 132.1451673,
            }
            .into(),
            ..Default::default()
        })
        .fields(
            fields::Type::BoardingPass {
                pass_fields: fields::Fields {
                    ..Default::default()
                },
                transit_type: fields::TransitType::Air,
            }
            .add_header_field(fields::Content::new(
                "serial",
                "1122",
                fields::ContentOptions {
                    label: String::from("SERIAL").into(),
                    ..Default::default()
                },
            ))
            .add_header_field(fields::Content::new(
                "number",
                "0011223344",
                fields::ContentOptions {
                    label: String::from("NUMBER").into(),
                    text_alignment: fields::TextAlignment::Right.into(),
                    ..Default::default()
                },
            ))
            .add_primary_field(fields::Content::new(
                "from",
                "UHWW",
                fields::ContentOptions {
                    label: String::from("FROM").into(),
                    text_alignment: fields::TextAlignment::Left.into(),
                    ..Default::default()
                },
            ))
            .add_primary_field(fields::Content::new(
                "to",
                "RKSI",
                fields::ContentOptions {
                    label: String::from("TO").into(),
                    text_alignment: fields::TextAlignment::Right.into(),
                    ..Default::default()
                },
            ))
            .add_auxiliary_field(fields::Content::new(
                "date_departure",
                "20.02.2024",
                fields::ContentOptions {
                    label: String::from("Departure date").into(),
                    ..Default::default()
                },
            )),
        )
        .build();

        let json = pass.make_json().unwrap();

        println!("{}", json);

        let json_expected = r#"{
  "formatVersion": 1,
  "organizationName": "Apple inc.",
  "description": "Example pass",
  "passTypeIdentifier": "com.example.pass",
  "teamIdentifier": "AA00AA0A0A",
  "serialNumber": "ABCDEFG1234567890",
  "groupingIdentifier": "com.example.pass.app",
  "foregroundColor": "rgb(250, 10, 10)",
  "backgroundColor": "rgb(255, 255, 255)",
  "logoText": "Test pass",
  "relevantDate": "2024-02-07T00:00:00+00:00",
  "expirationDate": "2024-02-08T00:00:00+00:00",
  "appLaunchURL": "testapp:param?index=1",
  "associatedStoreIdentifiers": [
    100
  ],
  "authenticationToken": "abcdefg01234567890abcdefg",
  "webServiceURL": "https://example.com/passes/",
  "suppressStripShine": false,
  "barcodes": [
    {
      "message": "Hello world!",
      "format": "PKBarcodeFormatQR",
      "altText": "test by test",
      "messageEncoding": "iso-8859-1"
    }
  ],
  "beacons": [
    {
      "proximityUUID": "e286373b-15b5-4f4e-bf91-e9e64787724a",
      "major": 2,
      "minor": 150,
      "relevantText": "The simple beacon"
    }
  ],
  "locations": [
    {
      "latitude": 37.334606,
      "longitude": -122.009102,
      "relevantText": "Apple Park, Cupertino, CA, USA"
    }
  ],
  "maxDistance": 1000,
  "nfc": {
    "encryptionPublicKey": "ABCDEFG_0011223344556677889900",
    "message": "test message",
    "requiresAuthentication": false
  },
  "semantics": {
    "airlineCode": "EX123",
    "departureLocation": {
      "latitude": 43.3948533,
      "longitude": 132.1451673
    }
  },
  "boardingPass": {
    "auxiliaryFields": [
      {
        "key": "date_departure",
        "value": "20.02.2024",
        "label": "Departure date"
      }
    ],
    "backFields": [],
    "headerFields": [
      {
        "key": "serial",
        "value": "1122",
        "label": "SERIAL"
      },
      {
        "key": "number",
        "value": "0011223344",
        "label": "NUMBER",
        "textAlignment": "PKTextAlignmentRight"
      }
    ],
    "primaryFields": [
      {
        "key": "from",
        "value": "UHWW",
        "label": "FROM",
        "textAlignment": "PKTextAlignmentLeft"
      },
      {
        "key": "to",
        "value": "RKSI",
        "label": "TO",
        "textAlignment": "PKTextAlignmentRight"
      }
    ],
    "secondaryFields": [],
    "transitType": "PKTransitTypeAir"
  }
}"#;

        assert_eq!(json_expected, json);

        // Deserialization test
        let pass: Pass = Pass::from_json(json_expected).unwrap();
        let json = pass.make_json().unwrap();
        assert_eq!(json_expected, json);
    }
}

// For serde skipping - if boolean false
fn _is_false(b: &bool) -> bool {
    !b
}

// For serde skipping - if boolean true
fn _is_true(b: &bool) -> bool {
    *b
}

// For serde (default boolean - true)
const fn _default_true() -> bool {
    true
}