pub use omni_schema_derive::Schema;
pub use omni_schema_core::{
Schema as SchemaImpl,
SchemaRegistry,
SchemaError, SchemaResult,
types::{
EnumDefinition, EnumRepresentation, EnumVariant, FieldDefinition,
NewtypeDefinition, PrimitiveType, SchemaDefinition, SchemaType,
StructDefinition, StructField, TypeReference, VariantData,
},
attributes::{
EnumAttribute, FieldAttribute, RenameRule, SchemaAttributes,
TypeAttribute, VariantAttribute,
},
ExternalSchema, FlattenableSchema,
};
pub mod formats {
#[cfg(feature = "json-schema")]
pub use omni_schema_core::formats::json_schema;
#[cfg(feature = "openapi")]
pub use omni_schema_core::formats::openapi;
#[cfg(feature = "graphql")]
pub use omni_schema_core::formats::graphql;
#[cfg(feature = "protobuf")]
pub use omni_schema_core::formats::protobuf;
#[cfg(feature = "typescript")]
pub use omni_schema_core::formats::typescript;
#[cfg(feature = "avro")]
pub use omni_schema_core::formats::avro;
pub use omni_schema_core::formats::format_ids;
pub use omni_schema_core::formats::utils;
}
pub use omni_schema_core::registry::RegistryConfig;
#[cfg(feature = "uuid-support")]
pub use uuid;
#[cfg(feature = "chrono-support")]
pub use chrono;
#[cfg(feature = "url-support")]
pub use url;
#[cfg(feature = "serde-compat")]
pub use serde;
pub use serde_json;
pub mod prelude {
pub use super::Schema;
pub use omni_schema_core::{Schema as SchemaImpl, SchemaRegistry};
#[cfg(feature = "json-schema")]
pub use omni_schema_core::formats::json_schema;
#[cfg(feature = "typescript")]
pub use omni_schema_core::formats::typescript;
#[cfg(feature = "graphql")]
pub use omni_schema_core::formats::graphql;
#[cfg(feature = "protobuf")]
pub use omni_schema_core::formats::protobuf;
#[cfg(feature = "openapi")]
pub use omni_schema_core::formats::openapi;
#[cfg(feature = "avro")]
pub use omni_schema_core::formats::avro;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_schema_definition_creation() {
let def = SchemaDefinition::new(
"TestType",
SchemaType::Primitive(PrimitiveType::String),
)
.with_description("A test type");
assert_eq!(def.name, "TestType");
assert!(def.description.is_some());
}
#[test]
fn test_registry_creation() {
let registry = SchemaRegistry::new()
.with_title("Test API")
.with_version("1.0.0");
assert_eq!(registry.config().title, Some("Test API".to_string()));
assert_eq!(registry.config().version, Some("1.0.0".to_string()));
}
#[test]
fn test_struct_definition() {
let struct_def = StructDefinition::new()
.with_field(
"name",
StructField::new(
SchemaType::Primitive(PrimitiveType::String),
"name",
)
.with_description("The name field"),
);
assert_eq!(struct_def.fields.len(), 1);
assert!(struct_def.fields.contains_key("name"));
}
#[test]
fn test_enum_definition() {
let enum_def = EnumDefinition::new(EnumRepresentation::External)
.with_variant(EnumVariant::unit("Active"))
.with_variant(EnumVariant::unit("Inactive"));
assert_eq!(enum_def.variants.len(), 2);
assert!(enum_def.is_simple_enum());
}
}