vld-openapi 0.8.0

OpenAPI bridges for the vld validation library: utoipa and schemars (aide) schemas from vld types, and a JSON Schema validator
Documentation

vld-openapi

crates.io docs.rs

Use vld schemas in utoipa, schemars and aide, so validation rules and OpenAPI docs come from one definition.

[dependencies]
vld = "0.8"
vld-openapi = { version = "0.8", features = ["utoipa-5"] }
utoipa = "5"
vld::schema! {
    #[derive(Debug)]
    pub struct CreateUser {
        pub name: String => vld::string().min(2).max(100),
        pub email: String => vld::string().email(),
    }
}
vld_openapi::utoipa5::impl_to_schema!(CreateUser); // utoipa ToSchema + IntoParams

#[derive(utoipa::OpenApi)]
#[openapi(components(schemas(CreateUser)))]
struct ApiDoc; // properties carry minLength, maxLength, format: email
Module Feature What it does
utoipa5 / utoipa6 utoipa-5 / utoipa-6 impl_to_schema!: utoipa ToSchema / IntoParams from a vld type
schemars0 / schemars1 schemars-0 / schemars-1 impl_json_schema! (vld → schemars::JsonSchema, also for aide 0.15 / 0.16) and impl_vld_parse! (schemars type → vld validation)
validator always validate JSON against a JSON Schema, inspect and combine schemas, to_openapi3

No feature is on by default; any set can be enabled together.

License

MIT