Skip to main content

Crate vld_schemars

Crate vld_schemars 

Source
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 + deserialize

Re-exports§

pub use schemars;
pub use vld;

Modules§

prelude

Macros§

impl_json_schema
Implement schemars::JsonSchema for a type that has a json_schema() associated function (generated by vld::schema! or #[derive(Validate)]).
impl_vld_parse
Implement vld::schema::VldParse and SchemarsValidate for a type that derives schemars::JsonSchema, serde::Serialize, and serde::Deserialize.

Structs§

PropertyInfo
Information about a single property in a JSON Schema object.

Enums§

VldSchemarsError
Error returned by schemars → vld validation.

Traits§

SchemarsValidate
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::Schema for a type implementing schemars::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::Schema into one using allOf.
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::Schema to a serde_json::Value.
schemas_equal
Check if two JSON Schema values are structurally equal.
validate_with_schema
Validate a serde_json::Value against a JSON Schema.
validate_with_schemars
Validate a serde_json::Value against a schemars::Schema.
vld_schema_to_schemars
Generate a schemars::Schema from a vld type that has a json_schema() method.
vld_to_schemars
Convert a serde_json::Value (JSON Schema produced by vld) into a schemars::Schema.