Skip to main content

Crate vld_utoipa

Crate vld_utoipa 

Source
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_paramsDeprecated
Deprecated alias for impl_to_schema!.
impl_to_schema
Bridge a vld type to utoipa (ToSchema + IntoParams when applicable).
impl_to_schema_pathDeprecated
Deprecated — use #[into_params(parameter_in = Path)] + impl_to_schema!.
impl_to_schema_queryDeprecated
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 by vld into a utoipa::openapi::RefOr<Schema>.
parameter_in_from_str
Map a parameter location hint from vld::json_schema::OpenApiParameterIn to utoipa.