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_
into_ params Deprecated - Deprecated alias for
impl_to_schema!. - impl_
to_ schema - Bridge a vld type to utoipa (
ToSchema+IntoParamswhen applicable). - impl_
to_ schema_ path Deprecated - Deprecated — use
#[into_params(parameter_in = Path)]+impl_to_schema!. - impl_
to_ schema_ query Deprecated - Deprecated — use
#[into_params(parameter_in = Query)]+impl_to_schema!.
Functions§
- json_
schema_ to_ params - Convert a vld object
json_schema()into OpenAPI path/query parameters. - json_
schema_ to_ schema - Convert a
serde_json::Value(JSON Schema) produced byvldinto autoipa::openapi::RefOr<Schema>. - parameter_
in_ from_ str - Map a parameter location hint from
vld::json_schema::OpenApiParameterInto utoipa.