Expand description
§vld-aide — Bridge between vld and aide / schemars
This crate lets you use vld validation schemas as the single source of truth
for both runtime validation and OpenAPI documentation generated by
aide (which uses schemars internally).
Instead of duplicating schema definitions with #[derive(JsonSchema)] and
vld::schema!, you define validation rules once and get schemars compatibility
for free.
§Quick Start
use vld::prelude::*;
use vld_aide::impl_json_schema;
// 1. Define your validated struct as usual
vld::schema! {
#[derive(Debug)]
pub struct User {
pub name: String => vld::string().min(2).max(50),
pub email: String => vld::string().email(),
}
}
// 2. Bridge to schemars — one line
impl_json_schema!(User);
// Now `User` implements `schemars::JsonSchema` and can be used in
// aide routers: `aide::axum::Json<User>` etc.§Converting arbitrary JSON Schema
use vld_aide::vld_to_schemars;
let vld_schema = serde_json::json!({
"type": "object",
"required": ["name"],
"properties": {
"name": { "type": "string", "minLength": 1 }
}
});
let schemars_schema = vld_to_schemars(&vld_schema);
// Returns `schemars::Schema`Re-exports§
pub use schemars;
Modules§
- prelude
- Prelude module — import everything you need.
Macros§
- impl_
json_ schema - Implement
schemars::JsonSchemafor a type that has ajson_schema()associated function (generated byvld::schema!with theopenapifeature enabled, or by#[derive(Validate)]).
Functions§
- vld_
to_ schemars - Convert a
serde_json::Value(JSON Schema) produced byvldinto aschemars::Schema.