Skip to main content

Crate rutmf

Crate rutmf 

Source
Expand description

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.

§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.

FeatureEnables
party, customer, product, orderdomain models (default)
ticket, alarmthe assurance domain: TMF621 tickets, TMF642 alarms
bill, account, usagemonetisation: TMF678 bills, TMF666 accounts, TMF635 rated usage
service, resourcethe inventory-side models — also on by default, because product needs them for its realizingService and supportingResource references
apithe transport-agnostic client layer
transport-reqwesta ready-made reqwest transport, with OAuth2 and retries
api-tmf620Product Catalog Management (TMF620 v5.0.0)
api-tmf621Trouble Ticket (TMF621 v5.0.1)
api-tmf642Alarm Management (TMF642 v5.0.1)
api-tmf666Account Management (TMF666 v5.0.0)
api-tmf635Product Usage Management (TMF635 v5.0.0)
api-tmf678Customer Bill (TMF678 v5.0.0)
api-tmf622Product Ordering (TMF622 v5.0.0)
api-tmf629Customer Management (TMF629 v5.0.1)
api-tmf632Party Management (TMF632 v5.0.0)
api-tmf634Resource Catalog Management (TMF634 v5.0.0)
api-tmf637Product Inventory (TMF637 v5.0.0)
api-tmf638Service Inventory (TMF638 v5.0.0)
api-tmf639Resource Inventory (TMF639 v5.0.0)
api-tmf669Party Role Management (TMF669 v5.0.0)
api-tmf679Product Offering Qualification (TMF679 v5.0.0)
serverimplement a TMF API: a store trait under a TMF630 handler
server-axuman axum Router over that handler
mockan in-process TMF server for tests
schemarsJsonSchema derives on every type
fulleverything above

Re-exports§

pub use jiff;

Modules§

accountaccount
Accounts: who is billed, and how — TMF666.
alarmalarm
Fault management: what the network is complaining about — TMF642.
apiapi
HTTP clients for the TM Forum Open APIs.
billbill
Billing: what the customer owes — TMF678.
core
Types shared by every TM Forum domain.
customercustomer
The customer domain.
mockmock
An in-process TM Forum server for tests.
orderorder
The ordering domain: product orders and their cancellation.
partyparty
The party domain: individuals and organizations.
prelude
The traits whose methods are otherwise invisible.
productproduct
The product domain: what is sold, and what a customer has.
resourceresource
The resource domain: what the network is made of.
serverserver
Implement a TM Forum API, rather than call one.
serviceservice
The service domain: what runs on the network.
ticketticket
The assurance domain: what went wrong, and who is fixing it.
usageusage
Usage: what a customer consumed, and what it was rated at — TMF635.

Constants§

TMF_VERSION
The TM Forum Open API major version this crate targets.