Move private crate exports into _private module

This commit is contained in:
Graham Esau 2024-08-29 19:47:19 +01:00
parent 441249a53b
commit 9bba81892f
6 changed files with 34 additions and 37 deletions

View file

@ -7,6 +7,9 @@ use serde_json::{json, map::Entry, Map, Value};
mod regex_syntax; mod regex_syntax;
mod rustdoc; mod rustdoc;
pub extern crate alloc;
pub extern crate serde_json;
pub use rustdoc::get_title_and_description; pub use rustdoc::get_title_and_description;
// Helper for generating schemas for flattened `Option` fields. // Helper for generating schemas for flattened `Option` fields.

View file

@ -34,12 +34,6 @@ use alloc::borrow::Cow;
#[cfg(feature = "schemars_derive")] #[cfg(feature = "schemars_derive")]
pub use 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)] #[doc(inline)]
pub use generate::SchemaGenerator; pub use generate::SchemaGenerator;
pub use schema::Schema; pub use schema::Schema;

View file

@ -99,7 +99,7 @@ macro_rules! json_schema {
( (
{$($json_object:tt)*} {$($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) => { (true) => {
$crate::Schema::from(true) $crate::Schema::from(true)

View file

@ -177,17 +177,17 @@ impl CommonAttrs {
if !self.examples.is_empty() { if !self.examples.is_empty() {
let examples = self.examples.iter().map(|eg| { let examples = self.examples.iter().map(|eg| {
quote! { quote! {
schemars::_serde_json::value::to_value(#eg()) schemars::_private::serde_json::value::to_value(#eg())
} }
}); });
mutators.push(quote! { 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 { for (k, v) in &self.extensions {
mutators.push(quote! { 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));
}); });
} }

View file

@ -62,11 +62,11 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
<#ty as schemars::JsonSchema>::always_inline_schema() <#ty as schemars::JsonSchema>::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() <#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() <#ty as schemars::JsonSchema>::schema_id()
} }
@ -106,10 +106,10 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
{ {
( (
quote! { quote! {
schemars::_alloc::borrow::Cow::Borrowed(#schema_base_name) schemars::_private::alloc::borrow::Cow::Borrowed(#schema_base_name)
}, },
quote! { quote! {
schemars::_alloc::borrow::Cow::Borrowed(::core::concat!( schemars::_private::alloc::borrow::Cow::Borrowed(::core::concat!(
::core::module_path!(), ::core::module_path!(),
"::", "::",
#schema_base_name #schema_base_name
@ -123,13 +123,13 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
} }
( (
quote! { quote! {
schemars::_alloc::borrow::Cow::Owned( schemars::_private::alloc::borrow::Cow::Owned(
schemars::_alloc::format!(#schema_name_fmt #(,#type_params=#type_params::schema_name())* #(,#const_params=#const_params)*) schemars::_private::alloc::format!(#schema_name_fmt #(,#type_params=#type_params::schema_name())* #(,#const_params=#const_params)*)
) )
}, },
quote! { quote! {
schemars::_alloc::borrow::Cow::Owned( schemars::_private::alloc::borrow::Cow::Owned(
schemars::_alloc::format!( schemars::_private::alloc::format!(
::core::concat!( ::core::concat!(
::core::module_path!(), ::core::module_path!(),
"::", "::",
@ -147,13 +147,13 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
schema_name_fmt.push_str(&"_and_{}".repeat(params.len() - 1)); schema_name_fmt.push_str(&"_and_{}".repeat(params.len() - 1));
( (
quote! { quote! {
schemars::_alloc::borrow::Cow::Owned( schemars::_private::alloc::borrow::Cow::Owned(
schemars::_alloc::format!(#schema_name_fmt #(,#type_params::schema_name())* #(,#const_params)*) schemars::_private::alloc::format!(#schema_name_fmt #(,#type_params::schema_name())* #(,#const_params)*)
) )
}, },
quote! { quote! {
schemars::_alloc::borrow::Cow::Owned( schemars::_private::alloc::borrow::Cow::Owned(
schemars::_alloc::format!( schemars::_private::alloc::format!(
::core::concat!( ::core::concat!(
::core::module_path!(), ::core::module_path!(),
"::", "::",
@ -180,11 +180,11 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
#[automatically_derived] #[automatically_derived]
#[allow(unused_braces)] #[allow(unused_braces)]
impl #impl_generics schemars::JsonSchema for #type_name #ty_generics #where_clause { impl #impl_generics schemars::JsonSchema for #type_name #ty_generics #where_clause {
fn schema_name() -> schemars::_alloc::borrow::Cow<'static, str> { fn schema_name() -> schemars::_private::alloc::borrow::Cow<'static, str> {
#schema_name #schema_name
} }
fn schema_id() -> schemars::_alloc::borrow::Cow<'static, str> { fn schema_id() -> schemars::_private::alloc::borrow::Cow<'static, str> {
#schema_id #schema_id
} }

View file

@ -93,12 +93,12 @@ pub fn expr_for_repr(cont: &Container) -> Result<SchemaExpr, syn::Error> {
let variant_idents = variants.iter().map(|v| &v.ident); let variant_idents = variants.iter().map(|v| &v.ident);
let mut schema_expr = SchemaExpr::from(quote!({ 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("type".into(), "integer".into());
map.insert( map.insert(
"enum".into(), "enum".into(),
schemars::_serde_json::Value::Array({ schemars::_private::serde_json::Value::Array({
let mut enum_values = schemars::_alloc::vec::Vec::new(); let mut enum_values = schemars::_private::alloc::vec::Vec::new();
#(enum_values.push((#enum_ident::#variant_idents as #repr_type).into());)* #(enum_values.push((#enum_ident::#variant_idents as #repr_type).into());)*
enum_values enum_values
}), }),
@ -157,12 +157,12 @@ fn type_for_schema(with_attr: &WithAttr) -> (syn::Type, Option<TokenStream>) {
true true
} }
fn schema_name() -> schemars::_alloc::borrow::Cow<'static, str> { fn schema_name() -> schemars::_private::alloc::borrow::Cow<'static, str> {
schemars::_alloc::borrow::Cow::Borrowed(#fn_name) schemars::_private::alloc::borrow::Cow::Borrowed(#fn_name)
} }
fn schema_id() -> schemars::_alloc::borrow::Cow<'static, str> { fn schema_id() -> schemars::_private::alloc::borrow::Cow<'static, str> {
schemars::_alloc::borrow::Cow::Borrowed(::core::concat!( schemars::_private::alloc::borrow::Cow::Borrowed(::core::concat!(
"_SchemarsSchemaWithFunction/", "_SchemarsSchemaWithFunction/",
::core::module_path!(), ::core::module_path!(),
"/", "/",
@ -213,12 +213,12 @@ fn expr_for_external_tagged_enum<'a>(
.partition(|v| v.is_unit() && v.attrs.is_default()); .partition(|v| v.is_unit() && v.attrs.is_default());
let unit_names = unit_variants.iter().map(|v| v.name()); let unit_names = unit_variants.iter().map(|v| v.name());
let unit_schema = SchemaExpr::from(quote!({ 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("type".into(), "string".into());
map.insert( map.insert(
"enum".into(), "enum".into(),
schemars::_serde_json::Value::Array({ schemars::_private::serde_json::Value::Array({
let mut enum_values = schemars::_alloc::vec::Vec::new(); let mut enum_values = schemars::_private::alloc::vec::Vec::new();
#(enum_values.push((#unit_names).into());)* #(enum_values.push((#unit_names).into());)*
enum_values enum_values
}), }),
@ -378,11 +378,11 @@ fn expr_for_adjacent_tagged_enum<'a>(
fn variant_subschemas(unique: bool, schemas: Vec<SchemaExpr>) -> SchemaExpr { fn variant_subschemas(unique: bool, schemas: Vec<SchemaExpr>) -> SchemaExpr {
let keyword = if unique { "oneOf" } else { "anyOf" }; let keyword = if unique { "oneOf" } else { "anyOf" };
quote!({ quote!({
let mut map = schemars::_serde_json::Map::new(); let mut map = schemars::_private::serde_json::Map::new();
map.insert( map.insert(
#keyword.into(), #keyword.into(),
schemars::_serde_json::Value::Array({ schemars::_private::serde_json::Value::Array({
let mut enum_values = schemars::_alloc::vec::Vec::new(); let mut enum_values = schemars::_private::alloc::vec::Vec::new();
#(enum_values.push(#schemas.to_value());)* #(enum_values.push(#schemas.to_value());)*
enum_values enum_values
}), }),