Expand description
§vld-schemars — Bidirectional bridge between vld and schemars
Many Rust libraries (aide, paperclip, okapi, utoipa-rapidoc, etc.) already use
schemars for JSON Schema generation. This crate
lets you share schema definitions between vld and the broader schemars
ecosystem — in both directions.
§vld → schemars
use vld::prelude::*;
use vld_schemars::impl_json_schema;
vld::schema! {
#[derive(Debug)]
pub struct User {
pub name: String => vld::string().min(2).max(50),
pub email: String => vld::string().email(),
}
}
impl_json_schema!(User);
// User now implements schemars::JsonSchema§schemars → vld (macro on type)
use vld_schemars::{impl_vld_parse, SchemarsValidate};
#[derive(Debug, serde::Serialize, serde::Deserialize, schemars::JsonSchema)]
struct User { name: String, age: u32 }
impl_vld_parse!(User);
let user = User { name: "Alice".into(), age: 30 };
user.vld_validate().unwrap(); // validate existing instance
let json = serde_json::json!({"name": "Alice", "age": 30});
let user = User::vld_parse(&json).unwrap(); // validate + deserializeRe-exports§
Modules§
Macros§
- impl_
json_ schema - Implement
schemars::JsonSchemafor a type that has ajson_schema()associated function (generated byvld::schema!or#[derive(Validate)]). - impl_
vld_ parse - Implement
vld::schema::VldParseandSchemarsValidatefor a type that derivesschemars::JsonSchema,serde::Serialize, andserde::Deserialize.
Structs§
- Property
Info - Information about a single property in a JSON Schema object.
Enums§
- VldSchemars
Error - Error returned by schemars → vld validation.
Traits§
- Schemars
Validate - Trait for types that can be validated using their
schemars::JsonSchema.
Functions§
- generate_
from_ schemars - Generate a vld-compatible JSON Schema value from a type implementing
schemars::JsonSchema. - generate_
schemars - Generate a root
schemars::Schemafor a type implementingschemars::JsonSchema. - get_
property - Get the property schema for a specific field.
- is_
required - Check if a field is required in a JSON Schema.
- list_
properties - Extract property information from a JSON Schema object.
- list_
properties_ schemars - Extract property info from a
schemars::Schema. - merge_
schemas - Merge two
schemars::Schemainto one usingallOf. - overlay_
constraints - Overlay additional constraints from one schema onto another.
- schema_
type - Get the “type” field from a JSON Schema.
- schemars_
to_ json - Convert a
schemars::Schemato aserde_json::Value. - schemas_
equal - Check if two JSON Schema values are structurally equal.
- validate_
with_ schema - Validate a
serde_json::Valueagainst a JSON Schema. - validate_
with_ schemars - Validate a
serde_json::Valueagainst aschemars::Schema. - vld_
schema_ to_ schemars - Generate a
schemars::Schemafrom a vld type that has ajson_schema()method. - vld_
to_ schemars - Convert a
serde_json::Value(JSON Schema produced byvld) into aschemars::Schema.