#![forbid(unsafe_code)]
#![doc = include_str!("../README.md")]
#[cfg(not(feature = "preserve_order"))]
pub type Map<K, V> = std::collections::BTreeMap<K, V>;
#[cfg(feature = "preserve_order")]
pub type Map<K, V> = indexmap::IndexMap<K, V>;
pub type Set<T> = std::collections::BTreeSet<T>;
#[cfg(not(feature = "preserve_order"))]
pub type MapEntry<'a, K, V> = std::collections::btree_map::Entry<'a, K, V>;
#[cfg(feature = "preserve_order")]
pub type MapEntry<'a, K, V> = indexmap::map::Entry<'a, K, V>;
mod flatten;
mod json_schema_impls;
mod ser;
#[macro_use]
mod macros;
#[doc(hidden)]
pub mod _private;
pub mod gen;
pub mod schema;
pub mod visit;
#[cfg(feature = "schemars_derive")]
extern crate schemars_derive;
#[cfg(feature = "schemars_derive")]
pub use schemars_derive::*;
#[doc(hidden)]
pub use serde_json as _serde_json;
use schema::Schema;
pub trait JsonSchema {
fn is_referenceable() -> bool {
true
}
fn schema_name() -> String;
fn json_schema(gen: &mut gen::SchemaGenerator) -> Schema;
#[doc(hidden)]
fn _schemars_private_non_optional_json_schema(gen: &mut gen::SchemaGenerator) -> Schema {
Self::json_schema(gen)
}
#[doc(hidden)]
fn _schemars_private_is_option() -> bool {
false
}
}
#[cfg(test)]
pub mod tests {
use super::*;
pub fn schema_object_for<T: JsonSchema>() -> schema::SchemaObject {
schema_object(schema_for::<T>())
}
pub fn schema_for<T: JsonSchema>() -> schema::Schema {
let mut gen = gen::SchemaGenerator::default();
T::json_schema(&mut gen)
}
pub fn schema_object(schema: schema::Schema) -> schema::SchemaObject {
match schema {
schema::Schema::Object(o) => o,
s => panic!("Schema was not an object: {:?}", s),
}
}
}