Skip to content

Commit

Permalink
Export Schema from crate root
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed May 12, 2024
1 parent 0708bac commit 78be631
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 57 deletions.
2 changes: 1 addition & 1 deletion schemars/examples/custom_serialization.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use schemars::schema::Schema;
use schemars::Schema;
use schemars::{gen::SchemaGenerator, schema_for, JsonSchema};
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion schemars/src/_private.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::gen::SchemaGenerator;
use crate::schema::Schema;
use crate::JsonSchema;
use crate::Schema;
use serde::Serialize;
use serde_json::Map;
use serde_json::Value;
Expand Down
2 changes: 1 addition & 1 deletion schemars/src/flatten.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use serde_json::map::Entry;
use serde_json::Value;

use crate::schema::*;
use crate::Schema;

impl Schema {
/// This function is only public for use by schemars_derive.
Expand Down
2 changes: 1 addition & 1 deletion schemars/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ There are two main types in this module:
* [`SchemaGenerator`], which manages the generation of a schema document.
*/

use crate::schema::*;
use crate::Schema;
use crate::{visit::*, JsonSchema};
use dyn_clone::DynClone;
use serde::Serialize;
Expand Down
4 changes: 1 addition & 3 deletions schemars/src/json_schema_impls/array.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::json_schema;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use std::borrow::Cow;

// Does not require T: JsonSchema.
Expand Down
4 changes: 1 addition & 3 deletions schemars/src/json_schema_impls/core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::json_schema;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use serde_json::Value;
use std::borrow::Cow;
use std::ops::{Bound, Range, RangeInclusive};
Expand Down
4 changes: 1 addition & 3 deletions schemars/src/json_schema_impls/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::json_schema;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use std::borrow::Cow;
use std::ffi::{CStr, CString, OsStr, OsString};

Expand Down
5 changes: 2 additions & 3 deletions schemars/src/json_schema_impls/maps.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use std::borrow::Cow;

macro_rules! map_impl {
Expand All @@ -20,7 +19,7 @@ macro_rules! map_impl {
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": "object",
"additionalProperties": gen.subschema_for::<V>(),
})
Expand Down
3 changes: 1 addition & 2 deletions schemars/src/json_schema_impls/nonzero_signed.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use crate::{JsonSchema, Schema};
use std::borrow::Cow;
use std::num::*;

Expand Down
2 changes: 1 addition & 1 deletion schemars/src/json_schema_impls/nonzero_unsigned.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::Schema;
use crate::JsonSchema;
use std::borrow::Cow;
use std::num::*;
Expand Down
11 changes: 5 additions & 6 deletions schemars/src/json_schema_impls/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use std::borrow::Cow;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use std::path::{Path, PathBuf};
Expand All @@ -19,7 +18,7 @@ macro_rules! simple_impl {
}

fn json_schema(_: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": $instance_type
})
}
Expand All @@ -38,7 +37,7 @@ macro_rules! simple_impl {
}

fn json_schema(_: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": $instance_type,
"format": $format
})
Expand Down Expand Up @@ -85,7 +84,7 @@ macro_rules! unsigned_impl {
}

fn json_schema(_: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": $instance_type,
"format": $format,
"minimum": 0
Expand Down Expand Up @@ -114,7 +113,7 @@ impl JsonSchema for char {
}

fn json_schema(_: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": "string",
"minLength": 1,
"maxLength": 1,
Expand Down
7 changes: 3 additions & 4 deletions schemars/src/json_schema_impls/sequences.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use std::borrow::Cow;

macro_rules! seq_impl {
Expand All @@ -21,7 +20,7 @@ macro_rules! seq_impl {
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": "array",
"items": gen.subschema_for::<T>(),
})
Expand All @@ -48,7 +47,7 @@ macro_rules! set_impl {
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": "array",
"uniqueItems": true,
"items": gen.subschema_for::<T>(),
Expand Down
4 changes: 1 addition & 3 deletions schemars/src/json_schema_impls/serdejson.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::json_schema;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use serde_json::{Map, Number, Value};
use std::borrow::Cow;
use std::collections::BTreeMap;
Expand Down
7 changes: 3 additions & 4 deletions schemars/src/json_schema_impls/time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use std::borrow::Cow;
use std::time::{Duration, SystemTime};

Expand All @@ -14,7 +13,7 @@ impl JsonSchema for Duration {
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": "object",
"required": ["secs", "nanos"],
"properties": {
Expand All @@ -35,7 +34,7 @@ impl JsonSchema for SystemTime {
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": "object",
"required": ["secs_since_epoch", "nanos_since_epoch"],
"properties": {
Expand Down
5 changes: 2 additions & 3 deletions schemars/src/json_schema_impls/tuple.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use std::borrow::Cow;

macro_rules! tuple_impls {
Expand All @@ -24,7 +23,7 @@ macro_rules! tuple_impls {
}

fn json_schema(gen: &mut SchemaGenerator) -> Schema {
crate::json_schema!({
json_schema!({
"type": "array",
"items": [
$(gen.subschema_for::<$name>()),+
Expand Down
8 changes: 4 additions & 4 deletions schemars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

mod flatten;
mod json_schema_impls;
mod schema;
mod ser;
#[macro_use]
mod macros;
Expand All @@ -12,7 +13,6 @@ mod macros;
#[doc(hidden)]
pub mod _private;
pub mod gen;
pub mod schema;
pub mod visit;

#[cfg(feature = "schemars_derive")]
Expand All @@ -26,7 +26,7 @@ pub use schemars_derive::*;
#[doc(hidden)]
pub use serde_json as _serde_json;

use schema::Schema;
pub use schema::Schema;

/// A type which can be described as a JSON Schema document.
///
Expand All @@ -51,7 +51,7 @@ use schema::Schema;
/// you will need to determine an appropriate name and ID for the type.
/// For non-generic types, the type name/path are suitable for this:
/// ```
/// use schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema};
/// use schemars::{gen::SchemaGenerator, Schema, JsonSchema};
/// use std::borrow::Cow;
///
/// struct NonGenericType;
Expand All @@ -77,7 +77,7 @@ use schema::Schema;
///
/// But generic type parameters which may affect the generated schema should typically be included in the name/ID:
/// ```
/// use schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema};
/// use schemars::{gen::SchemaGenerator, Schema, JsonSchema};
/// use std::{borrow::Cow, marker::PhantomData};
///
/// struct GenericType<T>(PhantomData<T>);
Expand Down
6 changes: 3 additions & 3 deletions schemars/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ macro_rules! json_schema {
(
{$($json_object:tt)*}
) => {
$crate::schema::Schema::try_from($crate::_serde_json::json!({$($json_object)*})).unwrap()
$crate::Schema::try_from($crate::_serde_json::json!({$($json_object)*})).unwrap()
};
(true) => {
$crate::schema::Schema::from(true)
$crate::Schema::from(true)
};
(false) => {
$crate::schema::Schema::from(false)
$crate::Schema::from(false)
};
}
6 changes: 2 additions & 4 deletions schemars/src/ser.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::gen::SchemaGenerator;
use crate::json_schema;
use crate::schema::*;
use crate::JsonSchema;
use crate::{json_schema, JsonSchema, Schema};
use serde_json::{Error, Map, Value};
use std::fmt::Display;

Expand Down Expand Up @@ -39,7 +37,7 @@ macro_rules! forward_to_subschema_for {
macro_rules! return_instance_type {
($fn:ident, $ty:ty, $instance_type:expr) => {
fn $fn(self, _value: $ty) -> Result<Self::Ok, Self::Error> {
Ok(crate::json_schema!({
Ok(json_schema!({
"type": $instance_type
}))
}
Expand Down
2 changes: 1 addition & 1 deletion schemars/tests/schema_with_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod util;
use schemars::JsonSchema;
use util::*;

fn schema_fn(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
fn schema_fn(gen: &mut schemars::gen::SchemaGenerator) -> schemars::Schema {
<bool>::json_schema(gen)
}

Expand Down
2 changes: 1 addition & 1 deletion schemars/tests/schema_with_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod util;
use schemars::JsonSchema;
use util::*;

fn schema_fn(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
fn schema_fn(gen: &mut schemars::gen::SchemaGenerator) -> schemars::Schema {
<bool>::json_schema(gen)
}

Expand Down
2 changes: 1 addition & 1 deletion schemars/tests/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pretty_assertions::assert_eq;
use schemars::visit::Visitor;
use schemars::{gen::SchemaSettings, schema::Schema, schema_for, JsonSchema};
use schemars::{gen::SchemaSettings, schema_for, JsonSchema, Schema};
use std::error::Error;
use std::fs;

Expand Down
6 changes: 3 additions & 3 deletions schemars_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
<#ty as schemars::JsonSchema>::schema_id()
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::Schema {
<#ty as schemars::JsonSchema>::json_schema(gen)
}

fn _schemars_private_non_optional_json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
fn _schemars_private_non_optional_json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::Schema {
<#ty as schemars::JsonSchema>::_schemars_private_non_optional_json_schema(gen)
}

Expand Down Expand Up @@ -182,7 +182,7 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
#schema_id
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::Schema {
#schema_expr
}
};
Expand Down
2 changes: 1 addition & 1 deletion schemars_derive/src/schema_exprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn type_for_schema(with_attr: &WithAttr) -> (syn::Type, Option<TokenStream>) {
))
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::Schema {
#fun(gen)
}
}
Expand Down

0 comments on commit 78be631

Please sign in to comment.