Expand description
§vld-utoipa — Bridge between vld and utoipa
This crate lets you use vld validation schemas as the single source of truth
for both runtime validation and OpenAPI documentation generated by
utoipa.
Instead of duplicating schema definitions with #[derive(ToSchema)] and
vld::schema!, you define validation rules once in vld and get utoipa
compatibility for free.
§Quick Start
use vld::prelude::*;
use vld_utoipa::impl_to_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 utoipa — one line
impl_to_schema!(User);
// Now `User` implements `utoipa::ToSchema` and can be used in
// `#[utoipa::path]` annotations.§Converting arbitrary JSON Schema
use vld_utoipa::json_schema_to_schema;
let json_schema = serde_json::json!({
"type": "object",
"required": ["name"],
"properties": {
"name": { "type": "string", "minLength": 1 }
}
});
let utoipa_schema = json_schema_to_schema(&json_schema);
// Returns `utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>`Re-exports§
pub use utoipa;
Modules§
- prelude
- Prelude module — import everything you need.
Macros§
- impl_
to_ schema - Implement
utoipa::PartialSchemaandutoipa::ToSchemafor a type that has ajson_schema()associated function (generated byvld::schema!with theopenapifeature enabled).
Functions§
- json_
schema_ to_ schema - Convert a
serde_json::Value(JSON Schema) produced byvldinto autoipa::openapi::RefOr<Schema>.