Skip to content

Commit

Permalink
Move private crate exports into _private module
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Aug 29, 2024
1 parent 441249a commit 9bba818
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 37 deletions.
3 changes: 3 additions & 0 deletions schemars/src/_private/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 0 additions & 6 deletions schemars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion schemars/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions schemars_derive/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}

Expand Down
28 changes: 14 additions & 14 deletions schemars_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
<#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()
}

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()
}

Expand Down Expand Up @@ -106,10 +106,10 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
{
(
quote! {
schemars::_alloc::borrow::Cow::Borrowed(#schema_base_name)
schemars::_private::alloc::borrow::Cow::Borrowed(#schema_base_name)
},
quote! {
schemars::_alloc::borrow::Cow::Borrowed(::core::concat!(
schemars::_private::alloc::borrow::Cow::Borrowed(::core::concat!(
::core::module_path!(),
"::",
#schema_base_name
Expand All @@ -123,13 +123,13 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
}
(
quote! {
schemars::_alloc::borrow::Cow::Owned(
schemars::_alloc::format!(#schema_name_fmt #(,#type_params=#type_params::schema_name())* #(,#const_params=#const_params)*)
schemars::_private::alloc::borrow::Cow::Owned(
schemars::_private::alloc::format!(#schema_name_fmt #(,#type_params=#type_params::schema_name())* #(,#const_params=#const_params)*)
)
},
quote! {
schemars::_alloc::borrow::Cow::Owned(
schemars::_alloc::format!(
schemars::_private::alloc::borrow::Cow::Owned(
schemars::_private::alloc::format!(
::core::concat!(
::core::module_path!(),
"::",
Expand All @@ -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));
(
quote! {
schemars::_alloc::borrow::Cow::Owned(
schemars::_alloc::format!(#schema_name_fmt #(,#type_params::schema_name())* #(,#const_params)*)
schemars::_private::alloc::borrow::Cow::Owned(
schemars::_private::alloc::format!(#schema_name_fmt #(,#type_params::schema_name())* #(,#const_params)*)
)
},
quote! {
schemars::_alloc::borrow::Cow::Owned(
schemars::_alloc::format!(
schemars::_private::alloc::borrow::Cow::Owned(
schemars::_private::alloc::format!(
::core::concat!(
::core::module_path!(),
"::",
Expand All @@ -180,11 +180,11 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
#[automatically_derived]
#[allow(unused_braces)]
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
}

fn schema_id() -> schemars::_alloc::borrow::Cow<'static, str> {
fn schema_id() -> schemars::_private::alloc::borrow::Cow<'static, str> {
#schema_id
}

Expand Down
26 changes: 13 additions & 13 deletions schemars_derive/src/schema_exprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
}),
Expand Down Expand Up @@ -157,12 +157,12 @@ fn type_for_schema(with_attr: &WithAttr) -> (syn::Type, Option<TokenStream>) {
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!(),
"/",
Expand Down Expand Up @@ -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
}),
Expand Down Expand Up @@ -378,11 +378,11 @@ fn expr_for_adjacent_tagged_enum<'a>(
fn variant_subschemas(unique: bool, schemas: Vec<SchemaExpr>) -> 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
}),
Expand Down

0 comments on commit 9bba818

Please sign in to comment.