#[derive(Debug, Clone, serde::Deserialize)]
pub struct ReleaseResource {
pub id: uuid::Uuid,
#[serde(rename = "type")]
pub resource_type: String,
pub attributes: ReleaseAttributes,
}
#[derive(Debug, Clone, serde::Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ReleaseAttributes {
pub product_id: uuid::Uuid,
pub name: Option<String>,
pub version: String,
pub channel: String,
pub status: String,
#[serde(default)]
pub tag: Option<String>,
pub metadata: serde_json::Value,
#[serde(rename = "created")]
pub created: chrono::DateTime<chrono::Utc>,
#[serde(rename = "updated")]
pub updated: chrono::DateTime<chrono::Utc>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn deserializes_the_camel_case_attribute_names() {
let json = serde_json::json!({
"type": "releases",
"id": "01926b3e-0000-7000-8000-000000000000",
"attributes": {
"productId": "01926b3e-1111-7000-8000-000000000000",
"name": "Acme 2.0",
"version": "2.0.0",
"channel": "stable",
"status": "PUBLISHED",
"tag": "ga",
"metadata": {},
"created": "2026-01-01T00:00:00Z",
"updated": "2026-01-01T00:00:00Z",
}
});
let release: ReleaseResource = serde_json::from_value(json).unwrap();
assert_eq!(release.resource_type, "releases");
assert_eq!(release.attributes.version, "2.0.0");
assert_eq!(release.attributes.tag.as_deref(), Some("ga"));
}
#[test]
fn an_absent_tag_decodes_rather_than_erroring() {
let json = serde_json::json!({
"type": "releases",
"id": "01926b3e-0000-7000-8000-000000000000",
"attributes": {
"productId": "01926b3e-1111-7000-8000-000000000000",
"name": null,
"version": "2.0.0",
"channel": "stable",
"status": "PUBLISHED",
"metadata": {},
"created": "2026-01-01T00:00:00Z",
"updated": "2026-01-01T00:00:00Z",
}
});
let release: ReleaseResource = serde_json::from_value(json).unwrap();
assert_eq!(release.attributes.tag, None);
}
}