diff --git a/schemars/src/_private/mod.rs b/schemars/src/_private/mod.rs index 404d015..613c9dc 100644 --- a/schemars/src/_private/mod.rs +++ b/schemars/src/_private/mod.rs @@ -7,6 +7,9 @@ use serde_json::{json, map::Entry, Map, Value}; mod regex_syntax; mod rustdoc; +pub extern crate alloc; +pub extern crate serde_json; + pub use rustdoc::get_title_and_description; // Helper for generating schemas for flattened `Option` fields. diff --git a/schemars/src/lib.rs b/schemars/src/lib.rs index ae3ebac..6b8e7e6 100644 --- a/schemars/src/lib.rs +++ b/schemars/src/lib.rs @@ -34,12 +34,6 @@ use alloc::borrow::Cow; #[cfg(feature = "schemars_derive")] pub use schemars_derive::*; -// Export crates so schemars_derive can use them -#[doc(hidden)] -pub extern crate alloc as _alloc; -#[doc(hidden)] -pub extern crate serde_json as _serde_json; - #[doc(inline)] pub use generate::SchemaGenerator; pub use schema::Schema; diff --git a/schemars/src/macros.rs b/schemars/src/macros.rs index 0de7117..90c4105 100644 --- a/schemars/src/macros.rs +++ b/schemars/src/macros.rs @@ -99,7 +99,7 @@ macro_rules! json_schema { ( {$($json_object:tt)*} ) => { - $crate::Schema::try_from($crate::_serde_json::json!({$($json_object)*})).unwrap() + $crate::Schema::try_from($crate::_private::serde_json::json!({$($json_object)*})).unwrap() }; (true) => { $crate::Schema::from(true) diff --git a/schemars_derive/src/attr/mod.rs b/schemars_derive/src/attr/mod.rs index 28bc192..fad3a19 100644 --- a/schemars_derive/src/attr/mod.rs +++ b/schemars_derive/src/attr/mod.rs @@ -177,17 +177,17 @@ impl CommonAttrs { if !self.examples.is_empty() { let examples = self.examples.iter().map(|eg| { quote! { - schemars::_serde_json::value::to_value(#eg()) + schemars::_private::serde_json::value::to_value(#eg()) } }); mutators.push(quote! { - schemars::_private::insert_metadata_property(&mut #SCHEMA, "examples", schemars::_serde_json::Value::Array([#(#examples),*].into_iter().flatten().collect())); + schemars::_private::insert_metadata_property(&mut #SCHEMA, "examples", schemars::_private::serde_json::Value::Array([#(#examples),*].into_iter().flatten().collect())); }); } for (k, v) in &self.extensions { mutators.push(quote! { - schemars::_private::insert_metadata_property(&mut #SCHEMA, #k, schemars::_serde_json::json!(#v)); + schemars::_private::insert_metadata_property(&mut #SCHEMA, #k, schemars::_private::serde_json::json!(#v)); }); } diff --git a/schemars_derive/src/lib.rs b/schemars_derive/src/lib.rs index 578f45c..1c331aa 100644 --- a/schemars_derive/src/lib.rs +++ b/schemars_derive/src/lib.rs @@ -62,11 +62,11 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result::always_inline_schema() } - fn schema_name() -> schemars::_alloc::borrow::Cow<'static, str> { + fn schema_name() -> schemars::_private::alloc::borrow::Cow<'static, str> { <#ty as schemars::JsonSchema>::schema_name() } - fn schema_id() -> schemars::_alloc::borrow::Cow<'static, str> { + fn schema_id() -> schemars::_private::alloc::borrow::Cow<'static, str> { <#ty as schemars::JsonSchema>::schema_id() } @@ -106,10 +106,10 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result syn::Result syn::Result syn::Result schemars::_alloc::borrow::Cow<'static, str> { + fn schema_name() -> schemars::_private::alloc::borrow::Cow<'static, str> { #schema_name } - fn schema_id() -> schemars::_alloc::borrow::Cow<'static, str> { + fn schema_id() -> schemars::_private::alloc::borrow::Cow<'static, str> { #schema_id } diff --git a/schemars_derive/src/schema_exprs.rs b/schemars_derive/src/schema_exprs.rs index dac1486..5fa8e67 100644 --- a/schemars_derive/src/schema_exprs.rs +++ b/schemars_derive/src/schema_exprs.rs @@ -93,12 +93,12 @@ pub fn expr_for_repr(cont: &Container) -> Result { let variant_idents = variants.iter().map(|v| &v.ident); let mut schema_expr = SchemaExpr::from(quote!({ - let mut map = schemars::_serde_json::Map::new(); + let mut map = schemars::_private::serde_json::Map::new(); map.insert("type".into(), "integer".into()); map.insert( "enum".into(), - schemars::_serde_json::Value::Array({ - let mut enum_values = schemars::_alloc::vec::Vec::new(); + schemars::_private::serde_json::Value::Array({ + let mut enum_values = schemars::_private::alloc::vec::Vec::new(); #(enum_values.push((#enum_ident::#variant_idents as #repr_type).into());)* enum_values }), @@ -157,12 +157,12 @@ fn type_for_schema(with_attr: &WithAttr) -> (syn::Type, Option) { true } - fn schema_name() -> schemars::_alloc::borrow::Cow<'static, str> { - schemars::_alloc::borrow::Cow::Borrowed(#fn_name) + fn schema_name() -> schemars::_private::alloc::borrow::Cow<'static, str> { + schemars::_private::alloc::borrow::Cow::Borrowed(#fn_name) } - fn schema_id() -> schemars::_alloc::borrow::Cow<'static, str> { - schemars::_alloc::borrow::Cow::Borrowed(::core::concat!( + fn schema_id() -> schemars::_private::alloc::borrow::Cow<'static, str> { + schemars::_private::alloc::borrow::Cow::Borrowed(::core::concat!( "_SchemarsSchemaWithFunction/", ::core::module_path!(), "/", @@ -213,12 +213,12 @@ fn expr_for_external_tagged_enum<'a>( .partition(|v| v.is_unit() && v.attrs.is_default()); let unit_names = unit_variants.iter().map(|v| v.name()); let unit_schema = SchemaExpr::from(quote!({ - let mut map = schemars::_serde_json::Map::new(); + let mut map = schemars::_private::serde_json::Map::new(); map.insert("type".into(), "string".into()); map.insert( "enum".into(), - schemars::_serde_json::Value::Array({ - let mut enum_values = schemars::_alloc::vec::Vec::new(); + schemars::_private::serde_json::Value::Array({ + let mut enum_values = schemars::_private::alloc::vec::Vec::new(); #(enum_values.push((#unit_names).into());)* enum_values }), @@ -378,11 +378,11 @@ fn expr_for_adjacent_tagged_enum<'a>( fn variant_subschemas(unique: bool, schemas: Vec) -> SchemaExpr { let keyword = if unique { "oneOf" } else { "anyOf" }; quote!({ - let mut map = schemars::_serde_json::Map::new(); + let mut map = schemars::_private::serde_json::Map::new(); map.insert( #keyword.into(), - schemars::_serde_json::Value::Array({ - let mut enum_values = schemars::_alloc::vec::Vec::new(); + schemars::_private::serde_json::Value::Array({ + let mut enum_values = schemars::_private::alloc::vec::Vec::new(); #(enum_values.push(#schemas.to_value());)* enum_values }),