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
//! Ergonomic, **v5-first** Rust types and clients for the TM Forum Open APIs.
//!
//! `rutmf` models the TM Forum domain the way you would model it by hand:
//! typed references, real decimals for money, builders that only accept valid
//! shapes — with the HTTP clients layered strictly on top, so the data model is
//! usable on its own.
//!
//! > **Unofficial.** This crate is a community implementation of the publicly
//! > available, Apache-2.0-licensed TM Forum Open API specifications. It is not
//! > affiliated with, endorsed by, or certified by TM Forum. "TM Forum" is a
//! > trademark of TM Forum.
//!
//! # The domain model
//!
//! ```
//! use rutmf::product::ProductOffering;
//!
//! let offering = ProductOffering::builder()
//! .name("Business Internet")
//! .is_sellable(true)
//! .build();
//! ```
//!
//! Creating and updating are *different shapes* in TMF v5, and this crate keeps
//! them distinct so the compiler catches a malformed request:
//!
//! ```
//! use rutmf::core::Timestamp;
//! use rutmf::product::ProductOfferingCreate;
//!
//! // `name`, `lifecycle_status` and `last_update` are required on create —
//! // omitting one is a compile error, not a 400 from the server.
//! let body = ProductOfferingCreate::builder()
//! .name("Business Internet")
//! .lifecycle_status("Active")
//! .last_update(Timestamp::now())
//! .build();
//! ```
//!
//! # Round-trip fidelity
//!
//! Real TMF payloads carry vendor extensions, and a library that silently drops
//! them is unusable as integration middleware. Every entity captures unknown
//! members in [`Extensions`], preserving their relative order:
//!
//! ```
//! use rutmf::product::ProductOffering;
//!
//! let json = r#"{"id":"7655","name":"Basic Firewall","@type":"ProductOffering","x-vendor":{"tier":2}}"#;
//! let offering: ProductOffering = serde_json::from_str(json).unwrap();
//!
//! assert_eq!(offering.extensions.get("x-vendor").unwrap()["tier"], 2);
//!
//! let back = serde_json::to_value(&offering).unwrap();
//! assert_eq!(back, serde_json::from_str::<serde_json::Value>(json).unwrap());
//! ```
//!
//! ## What is guaranteed, precisely
//!
//! Decoding then re-encoding any payload is **lossless by value**:
//!
//! - every member present in the input with a value is present in the output,
//! with an equal value — including members this crate has no typed field for;
//! - members within [`Extensions`] keep their relative order;
//! - **no member is invented.** A payload that omits the spec-mandatory `@type`
//! comes back without one; ask the type what class it is instead, through
//! `type_name()`. Anything the crate *builds* declares its class, because a
//! request without `@type` is the one a server rejects;
//! - a timestamp keeps the UTC offset it arrived with, so
//! `2020-09-23T16:42:23-04:00` does not come back as `20:42:23Z` — the one
//! re-spelling is `+00:00`, which RFC 3339 writes as `Z`.
//!
//! It is *not* byte-for-byte. Members this crate knows about are emitted in
//! struct-declaration order rather than input order; JSON number formatting is
//! normalised; and a timestamp's fractional seconds are re-emitted in SI groups,
//! so `.96747` becomes `.967470`. Compare monetary values as decimals. A
//! [`serde_json::Number`] can retain distinct spellings of the same value.
//!
//! ## The one exception: an explicit `null`
//!
//! `{"description": null}` on a **modelled** member reads as absence and is not
//! re-emitted: `Option<T>` has two states where that needs three, and a
//! three-state type on every field would cost every caller for a distinction
//! the v5 schemas make almost nowhere. A `null` on an unmodelled member lands in
//! [`Extensions`] and does round-trip.
//!
//! Where the distinction is real — RFC 7386 makes `null` how a **merge patch**
//! removes a member — the `…Update` types say it:
//!
//! ```
//! use rutmf::product::ProductOfferingUpdate;
//!
//! let update = ProductOfferingUpdate::builder()
//! .name("Business Internet")
//! .build()
//! .deleting("description");
//!
//! assert!(update.deletes("description"));
//! ```
//!
//! This is enforced over **all 610 vendored TM Forum examples**, every one of
//! them, by `tests/conformance.rs`.
//!
//! ## Round-tripping is not coverage
//!
//! An unknown member survives in [`Extensions`] whether or not the model
//! understands it, so a payload round-trips perfectly even if the typed model
//! misses half of it. `tests/coverage.rs` is what closes that gap: it reads the
//! pinned `OpenAPI` documents and fails if any specified member has no typed
//! field, if any typed field is absent from the specification, if requiredness
//! disagrees, or if a member the specification gives a closed vocabulary is
//! typed as a `String` rather than an enumeration. It checks **219 Rust types
//! against 490 v5 schemas**. Both suites are needed, and neither substitutes for
//! the other.
//!
//! [`Extensions`]: crate::core::Extensions
//!
//! # Feature flags
//!
//! Domain models are enabled by default and pull in no I/O. Clients are opt-in,
//! so `cargo add rutmf` never drags in a TLS stack.
//!
//! | Feature | Enables |
//! |---|---|
//! | `party`, `customer`, `product`, `order` | domain models (**default**) |
//! | `ticket`, `alarm` | the assurance domain: TMF621 tickets, TMF642 alarms |
//! | `bill`, `account`, `usage` | monetisation: TMF678 bills, TMF666 accounts, TMF635 rated usage |
//! | `service`, `resource` | the inventory-side models — also on by default, because `product` needs them for its `realizingService` and `supportingResource` references |
//! | `api` | the transport-agnostic client layer |
//! | `transport-reqwest` | a ready-made `reqwest` transport, with `OAuth2` and retries |
//! | `api-tmf620` | Product Catalog Management (TMF620 v5.0.0) |
//! | `api-tmf621` | Trouble Ticket (TMF621 v5.0.1) |
//! | `api-tmf642` | Alarm Management (TMF642 v5.0.1) |
//! | `api-tmf666` | Account Management (TMF666 v5.0.0) |
//! | `api-tmf635` | Product Usage Management (TMF635 v5.0.0) |
//! | `api-tmf678` | Customer Bill (TMF678 v5.0.0) |
//! | `api-tmf622` | Product Ordering (TMF622 v5.0.0) |
//! | `api-tmf629` | Customer Management (TMF629 v5.0.1) |
//! | `api-tmf632` | Party Management (TMF632 v5.0.0) |
//! | `api-tmf634` | Resource Catalog Management (TMF634 v5.0.0) |
//! | `api-tmf637` | Product Inventory (TMF637 v5.0.0) |
//! | `api-tmf638` | Service Inventory (TMF638 v5.0.0) |
//! | `api-tmf639` | Resource Inventory (TMF639 v5.0.0) |
//! | `api-tmf669` | Party Role Management (TMF669 v5.0.0) |
//! | `api-tmf679` | Product Offering Qualification (TMF679 v5.0.0) |
//! | `server` | *implement* a TMF API: a store trait under a TMF630 handler |
//! | `server-axum` | an `axum` `Router` over that handler |
//! | `mock` | an in-process TMF server for tests |
//! | `schemars` | `JsonSchema` derives on every type |
//! | `full` | everything above |
/// The date-time library behind [`core::Timestamp`], re-exported so the
/// version you build with is always the one the crate uses.
pub use jiff;
/// The traits whose methods are otherwise invisible.
///
/// `reference()` on a resource, `resolve()` on a `Ref`, `fetch()` on a client,
/// `register_listener()` on any of the fifteen — each lives on a trait, and
/// Rust does not offer a trait method until the trait is in scope.
///
/// **Traits, not types.** [`Query`] comes too, because those calls take one.
///
/// ```
/// use rutmf::prelude::*;
/// use rutmf::product::ProductOffering;
///
/// // `reference()` is `core::Entity`.
/// let offering = ProductOffering::builder().id("7655").name("Firewall").build();
/// assert_eq!(offering.reference().unwrap().id, "7655");
/// ```
///
/// Concrete types stay in their domain module: `rutmf::product::ProductOffering`
/// says which API it belongs to, and several of the fifteen declare a `Product`
/// or a `Category` of their own.
///
/// [`Query`]: crate::api::Query
/// The TM Forum Open API **major** version this crate targets.
///
/// This is the `v5` that appears in every API's URL path, and it is the whole
/// of the crate's version story at the major level: there is no v4 support and
/// no build flag that changes what a type means.
///
/// It is deliberately *not* the patch version. The covered APIs sit on
/// different patch releases — TMF621, TMF629 and TMF642 are at 5.0.1 while the rest are
/// at 5.0.0 — so the precise version each client was modelled from is a
/// per-API constant, `SPEC_VERSION`, next to that client's `API_PATH`:
///
/// ```
/// # #[cfg(feature = "api-tmf621")] {
/// assert_eq!(rutmf::api::tmf621::SPEC_VERSION, "5.0.1");
/// assert_eq!(rutmf::TMF_VERSION, "v5");
/// # }
/// ```
pub const TMF_VERSION: &str = "v5";