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
//! `ProductSpecification` — the technical definition behind an offering.
use crate::core::macros::{tmf_entity, tmf_patch_body, tmf_struct};
use crate::core::{
Attachment, CharacteristicSpecification, ExternalIdentifier, IntentSpecification, Policy, Ref,
RelatedParty, ServiceSpecification, TimePeriod, Timestamp,
};
use crate::resource::ResourceSpecification;
use super::Category;
tmf_struct! {
@name = "ProductSpecification", @ref = "ProductSpecificationRef";
/// The definition of a product: what it is, independent of how it is sold.
///
/// This is the **read model**. Use [`ProductSpecificationCreate`] for `POST`
/// and [`ProductSpecificationUpdate`] for `PATCH`.
pub struct ProductSpecification {
/// Server-assigned identifier.
id: String,
/// Canonical URI of this specification.
href: String,
/// Name of the specification.
name: String,
/// Narrative description.
description: String,
/// Version of the specification.
version: String,
/// When the specification was last changed.
last_update: Timestamp,
/// Lifecycle status, e.g. `Active`, `Retired`.
lifecycle_status: String,
/// Whether this specification bundles others.
is_bundle: bool,
/// Brand under which the product is sold.
brand: String,
/// Product number used within the enterprise.
product_number: String,
/// Period during which the specification is valid.
valid_for: TimePeriod,
/// Characteristics that products built from this spec may carry.
///
/// Note the v5 member name: `productSpecCharacteristic`, not v4's
/// `productSpecificationCharacteristic`.
product_spec_characteristic: Vec<CharacteristicSpecification>,
/// Relationships to other specifications.
product_specification_relationship: Vec<SpecificationRelationship>,
/// Specifications bundled by this one.
bundled_product_specification: Vec<BundledProductSpecification>,
/// Categories this specification is filed under.
category: Vec<Ref<Category>>,
/// Policies constraining the specification.
policy: Vec<Ref<Policy>>,
/// Service specifications this product is realised by — TMF633.
service_specification: Vec<Ref<ServiceSpecification>>,
/// Resource specifications this product is realised by — TMF634.
resource_specification: Vec<Ref<ResourceSpecification>>,
/// Intent specification governing this product — TMF921.
intent_specification: Ref<IntentSpecification>,
/// A JSON Schema describing products built from this specification.
target_product_schema: TargetProductSchema,
/// Parties related to this specification, e.g. the owner.
related_party: Vec<RelatedParty>,
/// Attachments such as datasheets.
attachment: Vec<Attachment>,
/// Identifiers for this specification in external systems.
external_identifier: Vec<ExternalIdentifier>,
}
}
tmf_entity!(ProductSpecification);
tmf_struct! {
@name = "ProductSpecification";
/// Body of a `POST /productSpecification` — the v5 `ProductSpecification_FVO`.
pub struct ProductSpecificationCreate {
@required {
/// Name of the specification. **Required on create.**
name: String,
/// Lifecycle status. **Required on create.**
lifecycle_status: String,
/// When the specification was last changed. **Required on create.**
last_update: Timestamp,
}
/// Client-supplied identifier, where the server permits one.
id: String,
/// Narrative description.
description: String,
/// Version of the specification.
version: String,
/// Whether this specification bundles others.
is_bundle: bool,
/// Brand under which the product is sold.
brand: String,
/// Product number used within the enterprise.
product_number: String,
/// Period during which the specification is valid.
valid_for: TimePeriod,
/// Characteristics that products built from this spec may carry.
product_spec_characteristic: Vec<CharacteristicSpecification>,
/// Relationships to other specifications.
product_specification_relationship: Vec<SpecificationRelationship>,
/// Specifications bundled by this one.
bundled_product_specification: Vec<BundledProductSpecification>,
/// Categories this specification is filed under.
category: Vec<Ref<Category>>,
/// Policies constraining the specification.
policy: Vec<Ref<Policy>>,
/// Service specifications this product is realised by.
service_specification: Vec<Ref<ServiceSpecification>>,
/// Resource specifications this product is realised by.
resource_specification: Vec<Ref<ResourceSpecification>>,
/// Intent specification governing this product.
intent_specification: Ref<IntentSpecification>,
/// A JSON Schema describing products built from this specification.
target_product_schema: TargetProductSchema,
/// Parties related to this specification.
related_party: Vec<RelatedParty>,
/// Attachments such as datasheets.
attachment: Vec<Attachment>,
/// Identifiers for this specification in external systems.
external_identifier: Vec<ExternalIdentifier>,
}
}
tmf_struct! {
@name = "ProductSpecification";
/// Body of a `PATCH /productSpecification/{id}` — the v5 `_MVO` schema.
pub struct ProductSpecificationUpdate {
/// New name.
name: String,
/// New description.
description: String,
/// New version.
version: String,
/// New lifecycle status.
lifecycle_status: String,
/// New bundle flag.
is_bundle: bool,
/// New brand.
brand: String,
/// New product number.
product_number: String,
/// New validity period.
valid_for: TimePeriod,
/// Replacement characteristics.
product_spec_characteristic: Vec<CharacteristicSpecification>,
/// Replacement relationships.
product_specification_relationship: Vec<SpecificationRelationship>,
/// Replacement bundled specifications.
bundled_product_specification: Vec<BundledProductSpecification>,
/// Replacement categories.
category: Vec<Ref<Category>>,
/// Replacement policies.
policy: Vec<Ref<Policy>>,
/// Replacement service specifications.
service_specification: Vec<Ref<ServiceSpecification>>,
/// Replacement resource specifications.
resource_specification: Vec<Ref<ResourceSpecification>>,
/// Replacement intent specification.
intent_specification: Ref<IntentSpecification>,
/// Replacement target product schema.
target_product_schema: TargetProductSchema,
/// Replacement related parties.
related_party: Vec<RelatedParty>,
/// Replacement attachments.
attachment: Vec<Attachment>,
/// Replacement external identifiers.
external_identifier: Vec<ExternalIdentifier>,
}
}
tmf_struct! {
@name = "ProductSpecificationRelationship";
/// A relationship from one product specification to another.
pub struct SpecificationRelationship {
/// Identifier of the related specification.
id: String,
/// URI of the related specification.
href: String,
/// Name of the related specification.
name: String,
/// Kind of relationship, e.g. `dependency`, `exclusivity`.
relationship_type: String,
/// Version of the related specification.
version: String,
/// Characteristics that qualify the relationship.
characteristic: Vec<CharacteristicSpecification>,
/// Period during which the relationship holds.
valid_for: TimePeriod,
@renamed {
/// The concrete class of the related specification.
"@referredType" referred_type: String,
}
}
}
tmf_struct! {
@name = "BundledProductSpecification";
/// A specification included in a bundled specification.
pub struct BundledProductSpecification {
/// Identifier of the bundled specification.
id: String,
/// URI of the bundled specification.
href: String,
/// Name of the bundled specification.
name: String,
/// Version of the bundled specification.
version: String,
/// Lifecycle status of the bundled specification.
lifecycle_status: String,
}
}
/// A JSON Schema describing the products built from a specification.
///
/// The v5 schema defines this with `@type` and `@schemaLocation` and nothing
/// else: the point of the object is the schema URI it carries. That is why it
/// is written out rather than declared with the usual macro — it is the one
/// entity with no `@baseType`.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize, bon::Builder)]
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[non_exhaustive]
pub struct TargetProductSchema {
/// The `@type` of the schema being pointed at.
#[serde(rename = "@type", default, skip_serializing_if = "Option::is_none")]
#[builder(into)]
pub at_type: Option<String>,
/// A URI to the JSON-Schema file.
#[serde(
rename = "@schemaLocation",
default,
skip_serializing_if = "Option::is_none"
)]
#[builder(into)]
pub at_schema_location: Option<String>,
/// Members not covered by the typed model, kept in document order.
#[serde(
flatten,
default,
skip_serializing_if = "crate::core::Extensions::is_empty"
)]
#[builder(default)]
pub extensions: crate::core::Extensions,
}
tmf_patch_body!(ProductSpecificationUpdate);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_v5_characteristic_member_is_product_spec_characteristic() {
// v4 spelled it `productSpecificationCharacteristic`. Carrying that
// name into a v5 type meant every characteristic a v5 server sent was
// swept into `extensions` and no typed access existed.
let json = r#"{"@type":"ProductSpecification","productSpecCharacteristic":[{"name":"Colour","@type":"CharacteristicSpecification"}]}"#;
let spec: ProductSpecification = serde_json::from_str(json).unwrap();
assert_eq!(spec.product_spec_characteristic.as_ref().unwrap().len(), 1);
assert!(spec.extensions.is_empty());
}
}