@@ -8,6 +8,7 @@ use std::collections::HashMap;
8
8
#[ derive(
9
9
Builder , Clone , CopyGetters , Debug , Deserialize , Eq , Getters , Setters , PartialEq , Serialize ,
10
10
) ]
11
+ #[ serde( rename_all = "camelCase" ) ]
11
12
#[ builder(
12
13
pattern = "owned" ,
13
14
setter( into, strip_option) ,
@@ -22,7 +23,6 @@ pub struct Descriptor {
22
23
/// This REQUIRED property contains the media type of the referenced
23
24
/// content. Values MUST comply with RFC 6838, including the naming
24
25
/// requirements in its section 4.2.
25
- #[ serde( rename = "mediaType" ) ]
26
26
#[ getset( get = "pub" , set = "pub" ) ]
27
27
media_type : MediaType ,
28
28
/// This REQUIRED property is the digest of the targeted content,
@@ -146,3 +146,37 @@ impl Descriptor {
146
146
}
147
147
}
148
148
}
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