poststation-api-icd 0.4.0

API types for poststation
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
//! Rest API version of types
//!
//! This uses Schemars instead of postcard-schema, and avoid types like `u64` that
//! will make JSON/JS sad.
//!
//! At some point in the future we will publish an OpenAPI spec for all available requests.
//! For now, here is a listing of all endpoints and an example CURL request for each of them.
//!
//! ## "Get Devices"
//!
//! ```sh
//! curl http://localhost:4444/api/devices -q -H "Accept: application/json"
//! ```
//!
//! ```json
//! [
//!   {
//!     "serial": "3836363937050630",
//!     "name": "XRAY-013",
//!     "is_connected": false,
//!     "manufacturer": "OneVariable",
//!     "product": "poststation-pico"
//!   },
//!   {
//!     "serial": "6E43B25479AC185C",
//!     "name": "YACHTY-312",
//!     "is_connected": true,
//!     "manufacturer": "Simulator",
//!     "product": "Product"
//!   },
//! ]
//! ```
//!
//! ## "Get Schemas"
//!
//! ```sh
//!  curl http://localhost:4444/api/devices/CA9FF06E058FF9A6/schemas -q -H "Accept: application/json"
//! ```
//!
//! Output: <https://gist.github.com/jamesmunns/0a533d8ed8ffbbc34c282da848a162fd>
//!
//! ## "Get Logs"
//!
//! ```sh
//! curl 'http://localhost:4444/api/devices/3836363937050630/logs?serial=3836363937050630&count=2' \
//! -q -H "Accept: application/json"
//! ```
//!
//! ```json
//! [
//!   {
//!     "uuidv7": "01936033-6231-71f2-9200-49361527b270",
//!     "msg": "Uptime: Duration { ticks: 1347000000 } freq: 125000000"
//!   },
//!   {
//!     "uuidv7": "01936033-6de8-7db0-8a7c-00563efac872",
//!     "msg": "Uptime: Duration { ticks: 1350000000 } freq: 125000000"
//!   }
//! ]
//! ```
//!
//! ## "Get Range of logs"
//!
//! This API is used as a paginated version of "Get Logs". You can use either a UTC millisecond timestamp
//! or the UUIDv7 of a log item as the "anchor" of the request, and then request N logs "Before" or "After" the
//! anchor (excluding the anchor itself).
//!
//! ### Using a UUIDv7 of a log entry as the anchor
//!
//! ```sh
//! curl 'http://localhost:4444/api/devices/3836363937050630/logs/range?serial=3836363937050630&count=4&uuid=01936032-e149-7e92-b4ca-f7e8a30e11cb&direction=After' \
//!   -q -H "Accept: application/json" | jq
//! ```
//!
//! ```json
//! [
//!   {
//!     "uuidv7": "01936033-1029-7e32-8b45-dc4595c98ee8",
//!     "msg": "Uptime: Duration { ticks: 1326000000 } freq: 125000000"
//!   },
//!   {
//!     "uuidv7": "01936033-0471-7912-9eaa-f3db32a47387",
//!     "msg": "Uptime: Duration { ticks: 1323000000 } freq: 125000000"
//!   },
//!   {
//!     "uuidv7": "01936032-f8b9-78e1-929e-99051b2bba64",
//!     "msg": "Uptime: Duration { ticks: 1320000000 } freq: 125000000"
//!   },
//!   {
//!     "uuidv7": "01936032-ed01-7ca0-99ad-f9ccac6c7e22",
//!     "msg": "Uptime: Duration { ticks: 1317000000 } freq: 125000000"
//!   }
//! ]
//! ```
//!
//! ### Using a unix millisecond timestamp as the anchor
//!
//! ```sh
//! curl 'http://localhost:4444/api/devices/3836363937050630/logs/range?serial=3836363937050630&count=4&unix_ms_ts=1732485767497&direction=After' \
//! -q -H "Accept: application/json" | jq
//!
//! ```json
//! [
//!   {
//!     "uuidv7": "01936033-0471-7912-9eaa-f3db32a47387",
//!     "msg": "Uptime: Duration { ticks: 1323000000 } freq: 125000000"
//!   },
//!   {
//!     "uuidv7": "01936032-f8b9-78e1-929e-99051b2bba64",
//!     "msg": "Uptime: Duration { ticks: 1320000000 } freq: 125000000"
//!   },
//!   {
//!     "uuidv7": "01936032-ed01-7ca0-99ad-f9ccac6c7e22",
//!     "msg": "Uptime: Duration { ticks: 1317000000 } freq: 125000000"
//!   },
//!   {
//!     "uuidv7": "01936032-e149-7e92-b4ca-f7e8a30e11cb",
//!     "msg": "Uptime: Duration { ticks: 1314000000 } freq: 125000000"
//!   }
//! ]
//! ```
//!
//! ## "Get Topic Messages"
//!
//! ```sh
//! curl 'http://localhost:4444/api/devices/CA9FF06E058FF9A6/topics?path=simulator/temperature&key=583A352440D70716&count=3' \
//!     -H "Accept: application/json"
//! ```
//!
//! ```json
//! [
//!   {
//!     "uuidv7": "01938dff-2bad-7ae1-9e3f-0ce6e2805ec0",
//!     "msg": {
//!       "temp": 3207.5660993151787
//!     }
//!   },
//!   {
//!     "uuidv7": "01938dff-2da1-7301-9654-7e3d338cf1eb",
//!     "msg": {
//!       "temp": 3210.7076919687684
//!     }
//!   },
//!   {
//!     "uuidv7": "01938dff-2f95-7b22-b71b-16dcd0c34f5a",
//!     "msg": {
//!       "temp": 3213.8492846223585
//!     }
//!   }
//! ]
//! ```
//!
//! ## "Proxy an endpoint request"
//!
//! ```sh
//! curl \
//!     -X POST \
//!     -H 'Content-Type: application/json' \
//!     -H "Accept: application/json" \
//!     'http://localhost:4444/api/devices/CA9FF06E058FF9A6/proxy' \
//!     -d '{
//!         "path": "postcard-rpc/ping",
//!         "req_key": "E8EDEF24F26C7C91",
//!         "resp_key": "E8EDEF24F26C7C91",
//!         "seq_no": 0,
//!         "body": 123
//!     }'
//! ```
//!
//! ```json
//! {
//!   "resp_key": "E8EDEF24F26C7C91",
//!   "seq_no": 0,
//!   "body": 123
//! }
//! ```
//!
//! ## "Proxy a topic publish"
//!
//! ```sh
//! curl \
//!     -X POST \
//!     -H 'Content-Type: application/json' \
//!     -H "Accept: application/json" \
//!     'http://localhost:4444/api/devices/CA9FF06E058FF9A6/publish' \
//!     -d '{
//!         "path": "some/topic/into/server",
//!         "topic_key": "E8EDEF24F26C7C91",
//!         "seq_no": 0,
//!         "body": { "some": "payload" }
//!     }'
//! ```
//!
//! ```json
//! {}
//! ```
//!
//! # "Subscribe to a stream of topic_out messages"
//!
//! This is a **WebSocket** endpoint, which gives you a live feed of a specific topic from a
//! specific device.
//!
//! ```sh
//! websocat "ws://localhost:4444/api/devices/CA9FF06E058FF9A6/listen?path=simulator/temperature&key=583A352440D70716" | jq
//! ```
//!
//! ```json
//! {
//!   "msg": {
//!     "temp": 2726.9024233159403
//!   },
//!   "seq_no": 868
//! }
//! {
//!   "msg": {
//!     "temp": 2730.0440159695304
//!   },
//!   "seq_no": 869
//! }
//! {
//!   "msg": {
//!     "temp": 2733.18560862312
//!   },
//!   "seq_no": 870
//! }
//! ```

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub struct DeviceData {
    pub serial: String,
    pub name: String,
    pub is_connected: bool,
    pub manufacturer: Option<String>,
    pub product: Option<String>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub struct LogRequest {
    pub count: u32,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub struct Log {
    pub uuidv7: Uuid,
    pub msg: String,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub struct LogRangeRequest {
    pub uuid: Option<Uuid>,
    pub unix_ms_ts: Option<u64>,
    pub direction: Direction,
    pub count: u32,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub enum Direction {
    Before,
    After,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub struct TopicRequest {
    pub path: String,
    pub key: foreign::Key,
    pub count: u32,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub struct TopicMsg {
    pub uuidv7: Uuid,
    pub msg: serde_json::Value,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub struct TopicStreamRequest {
    pub path: String,
    pub key: foreign::Key,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub struct TopicStreamMsg {
    pub stream_id: Uuid,
    pub msg: serde_json::Value,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Hash, JsonSchema)]
pub enum TopicStreamResult {
    Started(Uuid),
    NoDeviceKnown,
    DeviceDisconnected,
    NoSuchTopic,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ProxyRequest {
    pub path: String,
    pub req_key: foreign::Key,
    pub resp_key: foreign::Key,
    pub seq_no: u32,
    pub body: serde_json::Value,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct ProxyResponseOk {
    pub resp_key: foreign::Key,
    pub seq_no: u32,
    pub body: serde_json::Value,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
pub enum ProxyResponseError {
    WireErr {
        resp_key: foreign::Key,
        seq_no: u32,
        body: foreign::WireError,
    },
    OtherErr(String),
}

#[derive(Debug, PartialEq, Serialize, Deserialize, JsonSchema)]
pub struct PublishRequest {
    pub path: String,
    pub topic_key: foreign::Key,
    pub seq_no: u32,
    pub body: serde_json::Value,
}

/// These are types from other crates I'm pasting here just so I can impl JsonSchema on it
pub mod foreign {
    use std::collections::HashSet;

    use schema::OwnedNamedType;
    use schemars::JsonSchema;
    use serde::{Deserialize, Serialize};

    impl From<postcard_rpc::Key> for Key {
        fn from(value: postcard_rpc::Key) -> Self {
            Self(format!("{:016X}", u64::from_le_bytes(value.to_bytes())))
        }
    }

    impl TryFrom<Key> for postcard_rpc::Key {
        type Error = String;
        fn try_from(value: Key) -> Result<Self, Self::Error> {
            let Ok(val) = u64::from_str_radix(&value.0, 16) else {
                return Err(value.0);
            };
            unsafe { Ok(postcard_rpc::Key::from_bytes(val.to_le_bytes())) }
        }
    }

    #[derive(
        Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Serialize, Deserialize, Hash, JsonSchema,
    )]
    pub struct Key(String);

    /// The given frame was too long
    #[derive(Serialize, Deserialize, Debug, PartialEq, JsonSchema)]
    pub struct FrameTooLong {
        /// The length of the too-long frame
        pub len: u32,
        /// The maximum frame length supported
        pub max: u32,
    }

    /// The given frame was too short
    #[derive(Serialize, Deserialize, Debug, PartialEq, JsonSchema)]
    pub struct FrameTooShort {
        /// The length of the too-short frame
        pub len: u32,
    }

    /// A protocol error that is handled outside of the normal request type, usually
    /// indicating a protocol-level error
    #[derive(Serialize, Deserialize, Debug, PartialEq, JsonSchema)]
    pub enum WireError {
        /// The frame exceeded the buffering capabilities of the server
        FrameTooLong(FrameTooLong),
        /// The frame was shorter than the minimum frame size and was rejected
        FrameTooShort(FrameTooShort),
        /// Deserialization of a message failed
        DeserFailed,
        /// Serialization of a message failed, usually due to a lack of space to
        /// buffer the serialized form
        SerFailed,
        /// The key associated with this request was unknown
        UnknownKey,
        /// The server was unable to spawn the associated handler, typically due
        /// to an exhaustion of resources
        FailedToSpawn,
        /// The provided key is below the minimum key size calculated to avoid hash
        /// collisions, and was rejected to avoid potential misunderstanding
        KeyTooSmall,
    }

    /// A report describing the schema spoken by the connected device
    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
    pub struct SchemaReport {
        /// All custom types spoken by the device (on any endpoint or topic),
        /// as well as all primitive types. In the future, primitive types may
        /// be removed.
        pub types: HashSet<OwnedNamedType>,
        /// All incoming (client to server) topics reported by the device
        pub topics_in: Vec<TopicReport>,
        /// All outgoing (server to client) topics reported by the device
        pub topics_out: Vec<TopicReport>,
        /// All endpoints reported by the device
        pub endpoints: Vec<EndpointReport>,
    }

    impl From<postcard_rpc::host_client::SchemaReport> for SchemaReport {
        fn from(value: postcard_rpc::host_client::SchemaReport) -> Self {
            Self {
                types: value.types.iter().map(Into::into).collect(),
                topics_in: value.topics_in.into_iter().map(Into::into).collect(),
                topics_out: value.topics_out.into_iter().map(Into::into).collect(),
                endpoints: value.endpoints.into_iter().map(Into::into).collect(),
            }
        }
    }

    impl From<postcard_rpc::host_client::TopicReport> for TopicReport {
        fn from(value: postcard_rpc::host_client::TopicReport) -> Self {
            Self {
                path: value.path,
                key: value.key.into(),
                ty: (&value.ty).into(),
            }
        }
    }

    /// A description of a single Topic
    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
    pub struct TopicReport {
        /// The human readable path of the topic
        pub path: String,
        /// The Key of the topic (which hashes the path and type)
        pub key: Key,
        /// The schema of the type of the message
        pub ty: OwnedNamedType,
    }

    impl From<postcard_rpc::host_client::EndpointReport> for EndpointReport {
        fn from(value: postcard_rpc::host_client::EndpointReport) -> Self {
            Self {
                path: value.path,
                req_key: value.req_key.into(),
                req_ty: (&value.req_ty).into(),
                resp_key: value.resp_key.into(),
                resp_ty: (&value.resp_ty).into(),
            }
        }
    }

    /// A description of a single Endpoint
    #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
    pub struct EndpointReport {
        /// The human readable path of the endpoint
        pub path: String,
        /// The Key of the request (which hashes the path and type)
        pub req_key: Key,
        /// The schema of the request type
        pub req_ty: OwnedNamedType,
        /// The Key of the response (which hashes the path and type)
        pub resp_key: Key,
        /// The schema of the response type
        pub resp_ty: OwnedNamedType,
    }

    pub mod schema {
        //! Owned + JSON friendly Schema version

        use postcard_schema::schema::owned as real;
        use schemars::JsonSchema;
        use serde::{Deserialize, Serialize};
        use std::{boxed::Box, ops::Deref, string::String, vec::Vec};

        // ---

        /// The owned version of [`NamedType`]
        #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
        pub struct OwnedNamedType {
            /// The name of this type
            pub name: String,
            /// The type
            pub ty: OwnedDataModelType,
        }

        impl From<&real::OwnedNamedType> for OwnedNamedType {
            fn from(value: &real::OwnedNamedType) -> Self {
                Self {
                    name: value.name.to_string(),
                    ty: (&value.ty).into(),
                }
            }
        }

        // ---

        /// The owned version of [`DataModelType`]
        #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
        pub enum OwnedDataModelType {
            /// The `bool` Serde Data Model Type
            Bool,

            /// The `i8` Serde Data Model Type
            I8,

            /// The `u8` Serde Data Model Type
            U8,

            /// A variably encoded i16
            I16,

            /// A variably encoded i32
            I32,

            /// A variably encoded i64
            I64,

            /// A variably encoded i128
            I128,

            /// A variably encoded u16
            U16,

            /// A variably encoded u32
            U32,

            /// A variably encoded u64
            U64,

            /// A variably encoded u128
            U128,

            /// A variably encoded usize
            Usize,

            /// A variably encoded isize
            Isize,

            /// The `f32` Serde Data Model Type
            F32,

            /// The `f64 Serde Data Model Type
            F64,

            /// The `char` Serde Data Model Type
            Char,

            /// The `String` Serde Data Model Type
            String,

            /// The `&[u8]` Serde Data Model Type
            ByteArray,

            /// The `Option<T>` Serde Data Model Type
            Option(Box<OwnedNamedType>),

            /// The `()` Serde Data Model Type
            Unit,

            /// The "unit struct" Serde Data Model Type
            UnitStruct,

            /// The "newtype struct" Serde Data Model Type
            NewtypeStruct(Box<OwnedNamedType>),

            /// The "Sequence" Serde Data Model Type
            Seq(Box<OwnedNamedType>),

            /// The "Tuple" Serde Data Model Type
            Tuple(Vec<OwnedNamedType>),

            /// The "Tuple Struct" Serde Data Model Type
            TupleStruct(Vec<OwnedNamedType>),

            /// The "Map" Serde Data Model Type
            Map {
                /// The map "Key" type
                key: Box<OwnedNamedType>,
                /// The map "Value" type
                val: Box<OwnedNamedType>,
            },

            /// The "Struct" Serde Data Model Type
            Struct(Vec<OwnedNamedValue>),

            /// The "Enum" Serde Data Model Type (which contains any of the "Variant" types)
            Enum(Vec<OwnedNamedVariant>),

            /// A NamedType/OwnedNamedType
            Schema,
        }

        impl From<&real::OwnedDataModelType> for OwnedDataModelType {
            fn from(other: &real::OwnedDataModelType) -> Self {
                match other {
                    real::OwnedDataModelType::Bool => Self::Bool,
                    real::OwnedDataModelType::I8 => Self::I8,
                    real::OwnedDataModelType::U8 => Self::U8,
                    real::OwnedDataModelType::I16 => Self::I16,
                    real::OwnedDataModelType::I32 => Self::I32,
                    real::OwnedDataModelType::I64 => Self::I64,
                    real::OwnedDataModelType::I128 => Self::I128,
                    real::OwnedDataModelType::U16 => Self::U16,
                    real::OwnedDataModelType::U32 => Self::U32,
                    real::OwnedDataModelType::U64 => Self::U64,
                    real::OwnedDataModelType::U128 => Self::U128,
                    real::OwnedDataModelType::Usize => Self::Usize,
                    real::OwnedDataModelType::Isize => Self::Isize,
                    real::OwnedDataModelType::F32 => Self::F32,
                    real::OwnedDataModelType::F64 => Self::F64,
                    real::OwnedDataModelType::Char => Self::Char,
                    real::OwnedDataModelType::String => Self::String,
                    real::OwnedDataModelType::ByteArray => Self::ByteArray,
                    real::OwnedDataModelType::Option(o) => Self::Option(Box::new(o.deref().into())),
                    real::OwnedDataModelType::Unit => Self::Unit,
                    real::OwnedDataModelType::UnitStruct => Self::UnitStruct,
                    real::OwnedDataModelType::NewtypeStruct(nts) => {
                        Self::NewtypeStruct(Box::new(nts.deref().into()))
                    }
                    real::OwnedDataModelType::Seq(s) => Self::Seq(Box::new(s.deref().into())),
                    real::OwnedDataModelType::Tuple(t) => {
                        Self::Tuple(t.iter().map(|i| i.into()).collect())
                    }
                    real::OwnedDataModelType::TupleStruct(ts) => {
                        Self::TupleStruct(ts.iter().map(|i| i.into()).collect())
                    }
                    real::OwnedDataModelType::Map { key, val } => Self::Map {
                        key: Box::new(key.deref().into()),
                        val: Box::new(val.deref().into()),
                    },
                    real::OwnedDataModelType::Struct(s) => {
                        Self::Struct(s.iter().map(|i| i.into()).collect())
                    }
                    real::OwnedDataModelType::Enum(e) => {
                        Self::Enum(e.iter().map(|i| i.into()).collect())
                    }
                    real::OwnedDataModelType::Schema => Self::Schema,
                }
            }
        }

        // ---

        /// The owned version of [`DataModelVariant`]
        #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
        pub enum OwnedDataModelVariant {
            /// The "unit variant" Serde Data Model Type
            UnitVariant,
            /// The "newtype variant" Serde Data Model Type
            NewtypeVariant(Box<OwnedNamedType>),
            /// The "Tuple Variant" Serde Data Model Type
            TupleVariant(Vec<OwnedNamedType>),
            /// The "Struct Variant" Serde Data Model Type
            StructVariant(Vec<OwnedNamedValue>),
        }

        impl From<&real::OwnedDataModelVariant> for OwnedDataModelVariant {
            fn from(value: &real::OwnedDataModelVariant) -> Self {
                match value {
                    real::OwnedDataModelVariant::UnitVariant => Self::UnitVariant,
                    real::OwnedDataModelVariant::NewtypeVariant(d) => {
                        Self::NewtypeVariant(Box::new(d.deref().into()))
                    }
                    real::OwnedDataModelVariant::TupleVariant(d) => {
                        Self::TupleVariant(d.iter().map(|i| i.into()).collect())
                    }
                    real::OwnedDataModelVariant::StructVariant(d) => {
                        Self::StructVariant(d.iter().map(|i| i.into()).collect())
                    }
                }
            }
        }

        // ---

        /// The owned version of [`NamedValue`]
        #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
        pub struct OwnedNamedValue {
            /// The name of this value
            pub name: String,
            /// The type of this value
            pub ty: OwnedNamedType,
        }

        impl From<&real::OwnedNamedValue> for OwnedNamedValue {
            fn from(value: &real::OwnedNamedValue) -> Self {
                Self {
                    name: value.name.to_string(),
                    ty: (&value.ty).into(),
                }
            }
        }

        // ---

        /// The owned version of [`NamedVariant`]
        #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
        pub struct OwnedNamedVariant {
            /// The name of this variant
            pub name: String,
            /// The type of this variant
            pub ty: OwnedDataModelVariant,
        }

        impl From<&real::OwnedNamedVariant> for OwnedNamedVariant {
            fn from(value: &real::OwnedNamedVariant) -> Self {
                Self {
                    name: value.name.to_string(),
                    ty: (&value.ty).into(),
                }
            }
        }
    }
}