Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions typify-impl/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,19 @@ impl TypeEntry {
let text = value.to_string();
let type_path = syn::parse_str::<syn::TypePath>(type_name).unwrap();

// Deserialize the string to the type; the unwrap() is
// Deserialize the string to the type; the runtime expect() is
// unfortunate, but unavoidable without getting in the
// underpants of the serialized form of these built-in types.
quote! {
::serde_json::from_str::< #type_path >(#text).unwrap()
::serde_json::from_str::< #type_path >(#text)
.expect("invalid default provided")
}
}
TypeEntryDetails::JsonValue => {
let text = value.to_string();
quote! {
::serde_json::from_str::<::serde_json::Value>(#text).unwrap()
::serde_json::from_str::<::serde_json::Value>(#text)
.expect("invalid default provided")
}
}
TypeEntryDetails::Boolean => {
Expand Down Expand Up @@ -564,7 +566,8 @@ mod tests {
.map(|x| x.to_string()),
Some(
quote! {
::serde_json::from_str::<::uuid::Uuid>("\"not-a-uuid\"").unwrap()
::serde_json::from_str::<::uuid::Uuid>("\"not-a-uuid\"")
.expect("invalid default provided")
}
.to_string()
),
Expand Down
12 changes: 8 additions & 4 deletions typify-impl/tests/vega.out
Original file line number Diff line number Diff line change
Expand Up @@ -44272,8 +44272,10 @@ pub enum VoronoiTransformExtent {
impl ::std::default::Default for VoronoiTransformExtent {
fn default() -> Self {
VoronoiTransformExtent::Array([
::serde_json::from_str::<::serde_json::Value>("[-100000,-100000]").unwrap(),
::serde_json::from_str::<::serde_json::Value>("[100000,100000]").unwrap(),
::serde_json::from_str::<::serde_json::Value>("[-100000,-100000]")
.expect("invalid default provided"),
::serde_json::from_str::<::serde_json::Value>("[100000,100000]")
.expect("invalid default provided"),
])
}
}
Expand Down Expand Up @@ -45762,8 +45764,10 @@ pub mod defaults {
}
pub(super) fn voronoi_transform_extent() -> super::VoronoiTransformExtent {
super::VoronoiTransformExtent::Array([
::serde_json::from_str::<::serde_json::Value>("[-100000,-100000]").unwrap(),
::serde_json::from_str::<::serde_json::Value>("[100000,100000]").unwrap(),
::serde_json::from_str::<::serde_json::Value>("[-100000,-100000]")
.expect("invalid default provided"),
::serde_json::from_str::<::serde_json::Value>("[100000,100000]")
.expect("invalid default provided"),
])
}
pub(super) fn window_transform_frame() -> super::WindowTransformFrame {
Expand Down
11 changes: 7 additions & 4 deletions typify/tests/schemas/types-with-defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,20 +466,23 @@ pub mod defaults {
::serde_json::from_str::<::chrono::DateTime<::chrono::offset::Utc>>(
"\"1970-01-01T00:00:00Z\"",
)
.unwrap()
.expect("invalid default provided")
}
pub(super) fn mr_default_numbers_big_nullable() -> ::std::option::Option<::std::num::NonZeroU64>
{
::std::option::Option::Some(::std::num::NonZeroU64::new(1).unwrap())
}
pub(super) fn test_bed_any() -> ::std::vec::Vec<::serde_json::Value> {
vec![
::serde_json::from_str::<::serde_json::Value>("[8,6,7]").unwrap(),
::serde_json::from_str::<::serde_json::Value>("[5,3,0,9]").unwrap(),
::serde_json::from_str::<::serde_json::Value>("[8,6,7]")
.expect("invalid default provided"),
::serde_json::from_str::<::serde_json::Value>("[5,3,0,9]")
.expect("invalid default provided"),
]
}
pub(super) fn test_bed_id() -> ::uuid::Uuid {
::serde_json::from_str::<::uuid::Uuid>("\"abc123-is-this-a-uuid\"").unwrap()
::serde_json::from_str::<::uuid::Uuid>("\"abc123-is-this-a-uuid\"")
.expect("invalid default provided")
}
pub(super) fn u_int_container_max_path() -> super::UInt {
super::UInt(1_i64)
Expand Down
Loading