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
10 changes: 1 addition & 9 deletions typify-impl/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2067,8 +2067,7 @@ mod tests {
use serde_json::json;

use crate::{
test_util::validate_output, validate_builtin, Error, Name, TypeSpace, TypeSpaceImpl,
TypeSpaceSettings,
test_util::validate_output, Error, Name, TypeSpace, TypeSpaceImpl, TypeSpaceSettings,
};

#[track_caller]
Expand Down Expand Up @@ -2177,13 +2176,6 @@ mod tests {
validate_output::<Bar>();
}

// TODO we can turn this on once we generate proper sets.
#[ignore]
#[test]
fn test_set() {
validate_builtin!(std::collections::BTreeSet<u32>);
}

#[test]
fn test_low_default() {
let schema = SchemaObject {
Expand Down
2 changes: 1 addition & 1 deletion typify-impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ impl<'a> TypeStruct<'a> {
}

/// Get all information about each struct property.
pub fn properties_info(&'a self) -> impl Iterator<Item = TypeStructPropInfo> {
pub fn properties_info(&'a self) -> impl Iterator<Item = TypeStructPropInfo<'a>> {
self.details
.properties
.iter()
Expand Down
38 changes: 2 additions & 36 deletions typify-impl/src/test_util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 Oxide Computer Company
// Copyright 2025 Oxide Computer Company

use std::{any::type_name, collections::HashSet};

Expand All @@ -12,7 +12,7 @@ use syn::{
FieldsNamed, FieldsUnnamed, File, Type, TypePath, TypeTuple, Variant,
};

use crate::{output::OutputSpace, Name, RefKey, TypeId, TypeSpace};
use crate::{output::OutputSpace, RefKey, TypeId, TypeSpace};

pub(crate) fn get_type<T: JsonSchema>() -> (TypeSpace, TypeId) {
let schema = schema_for!(T);
Expand Down Expand Up @@ -141,40 +141,6 @@ fn decanonicalize_std_types(mut input: DeriveInput) -> DeriveInput {
input
}

#[macro_export]
macro_rules! validate_builtin {
($t:ty) => {
$crate::test_util::validate_builtin_impl::<$t>(stringify!($t))
};
}

#[track_caller]
pub(crate) fn validate_builtin_impl<T: JsonSchema>(name: &str) {
let schema = schema_for!(T);
let original_schema = schemars::schema::Schema::Object(schema.schema.clone());

let mut type_space = TypeSpace::default();
type_space
.add_ref_types(schema.definitions.clone())
.unwrap();
let (ty, _) = type_space
.convert_schema_object(Name::Unknown, &original_schema, &schema.schema)
.unwrap();

let output = ty.type_ident(&type_space, &None);

let actual = syn::parse2::<syn::Type>(output.clone()).unwrap();
let expected = syn::parse_str::<syn::Type>(name).unwrap();

// Make sure they match.
if let Err(err) = expected.syn_cmp(&actual, false) {
println!("{:#?}", schema);
println!("actual: {}", output);
println!("expected: {}", name);
panic!("{}", err);
}
}

pub(crate) trait SynCompare {
fn syn_cmp(&self, other: &Self, ignore_variant_names: bool) -> Result<(), String>;
}
Expand Down