rutmf
Ergonomic, v5-first Rust types and clients for the TM Forum Open APIs.
π Guides and documentation Β· π API reference
β οΈ Unofficial. A community implementation of the publicly available, Apache-2.0-licensed TM Forum Open API specifications. Not affiliated with, endorsed by, or certified by TM Forum. "TM Forum" is their trademark.
use ProductOffering;
let offering = builder
.name
.is_sellable
.build;
use ;
let page = client
.list_product_offerings
.await?;
The domain model and the HTTP clients are separate: rutmf::product has no idea
HTTP exists, and cargo add rutmf pulls in no TLS stack.
β¨ Design decisions
TM Forum's specifications leave a lot of room, and most of the work of a client library is in the choices. These are the ones this crate makes.
βοΈ Create and update are different types, because v5 says so. TMF v5 defines
each resource three times β the read model, an _FVO for POST, an _MVO for
PATCH β and they differ in which members exist and which are required.
Flattening the three into one all-optional struct leaves every mistake to be
caught by the server at runtime. Keeping them apart makes it a compile error:
use ProductOfferingCreate;
// `name`, `lifecycle_status` and `last_update` are required on create.
// Leaving one out does not compile.
let body = builder
.name
.lifecycle_status
.last_update
.build;
ProductOfferingUpdate has the mirror-image property: id, href and
lastUpdate are server-owned, so they are absent from the type entirely.
π Payloads survive a round trip. Real TMF deployments are full of vendor
extensions. Anything the crate has no field for is captured in extensions, in
document order, and re-emitted:
let json = r#"{"id":"7655","name":"Basic Firewall","@type":"ProductOffering","x-vendor":{"tier":2}}"#;
let offering: ProductOffering = from_str?;
assert_eq!;
assert_eq!;
Decoding then re-encoding is lossless by value: every input member with a
value comes back with an equal value, extension order is preserved, timestamps
keep their UTC offset, and nothing is invented β a payload that omits the
spec-mandatory @type comes back without one, because middleware must not add
members to what it relays.
One exception: an explicit null on a member the crate models reads as
absence and is not re-emitted β Option<T> has two states where that needs
three. A null on an unmodelled member round-trips through extensions. Where
the distinction is real β RFC 7386 makes null how a merge patch removes a
member β the β¦Update types say it:
let update = builder
.name
.build
.deleting; // β {"name": "β¦", "description": null}
𧬠A subclass is a value, not a string. TMF v5 gives a characteristic's value
shape its own class β IntegerCharacteristic, StringArrayCharacteristic, ten
more β and the subclass follows from the value, so it is derived:
use ;
let speed = new;
assert_eq!;
assert_eq!;
Six enumerations cover v5's seven polymorphic families, each with all() /
from_type_name / type_name, and tests/coverage.rs checks each against its
schema's discriminator.mapping in both directions.
π References know what they point at. Ref<ProductOffering> rather than a
stringly-typed identifier, so reference.resolve(&client, &query) hands back a
ProductOffering with no turbofish and no path string.
π A server cannot redirect your credentials. TMF payloads are full of URLs the
server wrote β the href of every β¦Ref, the Link: rel="next" of every paged
collection β and a transport attaches its bearer token to whatever URL it is
handed. Following those wherever they point would make any reference in any
response a place to put an attacker's host and collect a live token. So both are
checked against the client's own origin, and one that leaves it raises
Error::CrossOrigin instead:
// Within a deployment the TMF APIs share a host and differ by path, so this
// is the ordinary case and it just works.
let spec = reference.resolve.await?;
// Federating across hosts stays possible β it has to be asked for, so that
// trusting the other end is a decision rather than a default.
let spec = reference.resolve_cross_origin.await?;
π A PATCH cannot silently discard someone else's edit. A TMF PATCH is
read-modify-write, so two operators editing different members of one order each
overwrite the other β with 200 to both, and nothing to say so. A read can carry
the ETag the server issued, and writing through that tag makes the write
conditional:
use ;
let held: = client.inner.fetch.await?;
println!; // `Tagged<T>` derefs to `T`
// Refused with a 412 if anyone edited the order in between, rather than
// overwriting their change.
match held.update.await
The v5 documents declare no request headers, so this is RFC 9110 rather than TMF
β a server that ignores the precondition answers as it would without one, and
fetch reports whether a tag was issued. The server layer here is the other end
of the same exchange.
π° Money is a decimal. The v5 OAS types Money.value as number/float. Storing
money in binary floating point is a defect no matter what the schema says, so
values parse into rust_decimal::Decimal and re-emit as JSON numbers, keeping
integers integral.
π·οΈ A PATCH body cannot be labelled wrong. TMF v5 declares four PATCH content
types and pairs each with a body schema. Passing the body and the content type
separately lets you send a combination every server rejects, so they are one type
here:
use ;
client.update_product_offering.await?; // merge patch
client.update_product_offering.await?; // RFC 6902 list
client.update_product_offering.await?; // TMF JSONPath
π A prelude of traits, not types. reference(), resolve(), fetch() and
register_listener() each live on a trait, and Rust does not offer a trait
method until the trait is in scope. use rutmf::prelude::*; brings those in and
nothing else β concrete types stay in their domain module.
π§ͺ A TMF server for your tests. MockTmfServer implements the TMF630 collection
semantics in process β filtering with the comparison operators, sorting,
fields= projection, paging with count headers and a 206, merge patch and
atomic RFC 6902 patch β behind the same Transport seam the real clients use:
let server = new;
server.seed;
let client = new?;
let page = client.list_product_offerings.await?;
assert_eq!;
β Full guides, including queries, pagination, retries, OAuth2, events and the server layer.
π¦ Installation
cargo add rutmf
Domain models only, no I/O. To call an API:
cargo add rutmf --features api-tmf620,transport-reqwest
| Feature | Default | Enables |
|---|---|---|
party, customer, product, order, service, resource, ticket, alarm, bill, account |
β | domain models (pure types, no I/O) |
api |
transport-agnostic client layer | |
transport-reqwest |
ready-made reqwest transport, with OAuth2 client-credentials |
|
api-tmf620 β¦ api-tmf639 |
one per covered API, see below | |
server |
implement a TMF API: ResourceStore + TmfHandler |
|
server-axum |
ready-made axum Router for the above |
|
mock |
in-process TMF server for tests | |
schemars |
JsonSchema on every type |
|
full |
everything above |
MSRV is 1.88, verified in CI. The domain model builds for
wasm32-unknown-unknown.
πΊοΈ Coverage
Fourteen APIs are implemented end to end β domain types, client, mock, conformance fixtures and schema coverage:
| API | Version | Resources |
|---|---|---|
| TMF620 Product Catalog Management | v5.0.0 | ProductOffering, ProductSpecification, ProductOfferingPrice, ProductCatalog, Category, ImportJob, ExportJob |
| TMF621 Trouble Ticket | v5.0.1 | TroubleTicket, TroubleTicketSpecification |
| TMF622 Product Ordering | v5.0.0 | ProductOrder, CancelProductOrder |
| TMF629 Customer Management | v5.0.1 | Customer |
| TMF632 Party Management | v5.0.0 | Individual, Organization |
| TMF669 Party Role Management | v5.0.0 | PartyRole (supplier / consumer / producer / business partner), PartyRoleSpecification |
| TMF642 Alarm Management | v5.0.1 | Alarm + six task collections (ack, clear, comment, group, β¦) |
| TMF666 Account Management | v5.0.0 | Account (billing / financial / party / settlement), BillFormat, BillPresentationMedia, BillingCycleSpecification |
| TMF678 Customer Bill | v5.0.0 | CustomerBill, CustomerBillOnDemand, AppliedCustomerBillingRate, BillCycle |
| TMF634 Resource Catalog Management | v5.0.0 | ResourceCatalog, ResourceCategory, ResourceCandidate, ResourceSpecification, ImportJob, ExportJob |
| TMF637 Product Inventory Management | v5.0.0 | Product |
| TMF679 Product Offering Qualification | v5.0.0 | CheckProductOfferingQualification, QueryProductOfferingQualification |
| TMF638 Service Inventory Management | v5.0.0 | Service |
| TMF639 Resource Inventory Management | v5.0.0 | Resource (four subclasses), ResourceGraph |
Together these close the loop from shelf to network: browse a catalog (TMF620), identify who is buying (TMF632) and in what capacity (TMF669), engage them as a customer (TMF629), place the order (TMF622) β then find what the customer has (TMF637), what delivers it (TMF638) and what that runs on (TMF639). TMF634 is the catalog behind that last step, and TMF621/TMF642 are what you raise and what the network reports when any of it breaks.
Every CRUD resource carries the read / Create / Update triple and is
member-complete against its v5 schema. Every client implements HubOps for
event subscriptions.
βΉοΈ TMF641 Service Ordering and TMF688 Event Management are deliberately absent: neither has a v5 release, and this crate models v5 rather than pretending otherwise.
ποΈ Serving a TMF API
The other direction: you have the data, and you need to expose it as a conformant
TM Forum API. Implement five methods β none of them about HTTP β and TmfHandler
supplies TMF630 routing, filtering, sorting, fields= projection, paging with
count headers β offset/limit and the cursor pagination TMF621 and TMF639
declare β all four PATCH content types, ETag with If-Match on writes and
If-None-Match on reads, error bodies and status codes. Add
.with_max_page_size(100) and an unbounded collection GET stops being
something a caller can ask for.
let app = new.nest;
It serves /hub and raises the notifications a conformant server owes: a
write through the API becomes the right {Resource}{Kind}Event, matched against
each subscription's filter and addressed to its /listener/{eventName} URL. The
Notifier seam is the one part a deployment must supply β whether delivery is a
blocking POST, a queue publish or a retry loop.
Getting the right event name is not the one-liner it looks like. TMF621 and
TMF634 raise β¦StatusChangeEvent where the other twelve raise
β¦StateChangeEvent β and TMF634 does so over a member it still spells
lifecycleStatus, so the difference cannot be read off the resource. TMF638
separates an operational move (serviceOperatingStatusChangeEvent) from an
administrative one. A server that guesses raises names nobody has subscribed to,
and the failure is silent at both ends. So the spelling is read out of the
vendored /listener/β¦ paths, and tests/coverage.rs fails if all 157 of
them are not reproducible from the collection and the kind.
MockTmfServer is TmfHandler<MemoryStore> with a Notifier that records
instead of sending, so the test double and a real deployment run the same code
and cannot drift.
β Serving an API
π¬ Conformance
Three suites, because each is blind where the others see.
Against the examples. tests/fixtures/ holds 591 components.examples
values vendored verbatim from the TM Forum specification repositories
(Apache-2.0). Every one must parse and round-trip, and a separate test fails if
any fixture falls outside the mapping, so a new one cannot be a silently untested
one.
Against the schemas. Round-tripping proves nothing about coverage: an unknown
member survives in extensions whether or not the model understands it. So this
suite reads the vendored OpenAPI documents and checks 215 Rust types against
462 v5 schemas β member presence in both directions, member types, enumeration
values, requiredness, discriminator values against each schema's own
discriminator.mapping, that every reference names the class the spec declares,
that a member with a closed vocabulary is an enum rather than a String, that
a date-time member is a Timestamp, and that the fourteen specifications do not
disagree about a shared type.
Against the schemas, in reverse. "Every Rust type maps to a schema" is
satisfied by a crate modelling three schemas out of three thousand, so the suite
also asks the opposite: every schema the fourteen documents declare must be
modelled, or named in NOT_MODELLED with the reason. Nothing may be merely
absent. What that leaves out is the value arms of PlaceRefOrValue
(TMF673/674/675 geography and its GeoJSON geometry) and IntentRefOrValue
(TMF921) β APIs outside the fourteen, where the crate models the reference arm
and a value arm round-trips through extensions.
Against a running server. The other two check documents. This one reads each
vendored specification, discovers the collections and methods it declares, and
drives the server layer over a real socket for all 43 β asserting the status
codes, the count headers, the ETag, and that a missing resource is a 404
with a TMF630 body. It is spec-driven, so a new API extends it with no new test
code.
cargo test --test conformance
cargo test --test coverage --features schemars
cargo test --test server_conformance --features server-axum,transport-reqwest
cargo deny check runs in CI over the full dependency tree. Only rustls is
enabled as a TLS backend, and openssl-sys is banned outright.
π Examples
cargo run --example catalog_sync --features api-tmf620,mock
cargo run --example customer_onboarding --features api-tmf629,api-tmf632,mock
cargo run --example order_lifecycle --features api-tmf620,api-tmf622,mock
cargo run --example inventory_chain --features api-tmf634,api-tmf637,api-tmf638,api-tmf639,mock
cargo run --example assurance_workflow --features api-tmf621,api-tmf642,api-tmf678,mock
cargo run --example serve_catalog --features server-axum,api-tmf620,transport-reqwest
catalog_syncstreams a catalog and creates an offering.customer_onboardingwalks the TMF632 β TMF629 split.order_lifecycleruns catalog β order β fulfilment β cancellation, and shows a stalePATCHbeing refused instead of quietly discarding another operator's edit.inventory_chaingoes specification β resource β service β product.assurance_workflowis the loop after delivery: an alarm fires, the NOC acknowledges it, a ticket is raised and resolved, the alarm clears, and the bill is settled.serve_catalogimplements a TMF620 server and calls it with this crate's own client.
π‘ The first five need no network β they run against the in-process test server.
π§ Status
0.1 β early. The design is settled and proven against the specifications, and both directions work: calling a TM Forum API and serving one. The API surface will still change before 1.0. Pin an exact version.
Four things stand between here and 1.0: a release cycle of real use with the
module layout held still, conformance against TM Forum's own CTK (which needs
membership β the kit is not publicly pullable), one API modelled by somebody
else, and a settled decision on the #[non_exhaustive] trade-off. See
status and stability.
π Credit
The specifications themselves are published by TM Forum under Apache-2.0,
and the vendored documents and examples under specs/ and tests/fixtures/ are
their work.
π€ Contributing
See CONTRIBUTING.md. Adding an API is a tractable first contribution: the coverage suite's failure output is the to-do list.
π License
Dual-licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option. Vendored TM Forum specification material under specs/ and
tests/fixtures/ remains under its original Apache-2.0 license and copyright.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.