Skip to content

Commit 3d50978

Browse files
authored
Merge pull request #149 from tofay/artifactType
artifact_type on descriptor should be camelCased
2 parents 833976f + 9e73a8f commit 3d50978

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

src/image/descriptor.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::collections::HashMap;
88
#[derive(
99
Builder, Clone, CopyGetters, Debug, Deserialize, Eq, Getters, Setters, PartialEq, Serialize,
1010
)]
11+
#[serde(rename_all = "camelCase")]
1112
#[builder(
1213
pattern = "owned",
1314
setter(into, strip_option),
@@ -22,7 +23,6 @@ pub struct Descriptor {
2223
/// This REQUIRED property contains the media type of the referenced
2324
/// content. Values MUST comply with RFC 6838, including the naming
2425
/// requirements in its section 4.2.
25-
#[serde(rename = "mediaType")]
2626
#[getset(get = "pub", set = "pub")]
2727
media_type: MediaType,
2828
/// This REQUIRED property is the digest of the targeted content,
@@ -146,3 +146,37 @@ impl Descriptor {
146146
}
147147
}
148148
}
149+
150+
#[cfg(test)]
151+
mod tests {
152+
use super::*;
153+
use crate::image::Descriptor;
154+
155+
#[test]
156+
fn test_deserialize() {
157+
let descriptor_str = r#"{
158+
"mediaType": "application/vnd.oci.image.manifest.v1+json",
159+
"digest":"sha256:c2b8beca588702777e5f35dafdbeae9ec16c2bab802331f81cacd2a92f1d5356",
160+
"size":769,
161+
"annotations":{"org.opencontainers.image.created": "2023-10-11T22:37:26Z"},
162+
"artifactType":"application/spdx+json"}"#;
163+
let descriptor: Descriptor = serde_json::from_str(descriptor_str).unwrap();
164+
assert_eq!(descriptor.media_type, MediaType::ImageManifest);
165+
assert_eq!(
166+
descriptor.digest,
167+
"sha256:c2b8beca588702777e5f35dafdbeae9ec16c2bab802331f81cacd2a92f1d5356"
168+
);
169+
assert_eq!(descriptor.size, 769);
170+
assert_eq!(
171+
descriptor
172+
.annotations
173+
.unwrap()
174+
.get("org.opencontainers.image.created"),
175+
Some(&"2023-10-11T22:37:26Z".to_string())
176+
);
177+
assert_eq!(
178+
descriptor.artifact_type.unwrap(),
179+
MediaType::Other("application/spdx+json".to_string())
180+
);
181+
}
182+
}

0 commit comments

Comments
 (0)