vld-derive
Derive macro for the vld validation library.
Overview
Provides #[derive(Validate)] — a procedural macro that generates validate() and is_valid() methods for your structs based on #[vld(...)] field attributes.
This crate is not meant to be used directly. Enable the derive feature on the vld crate instead:
[]
= { = "0.1", = ["derive"] }
Quick start
use *;
use Validate;
Serde rename support
The macro automatically respects #[serde(rename)] and #[serde(rename_all)] attributes to determine the JSON field names used during validation:
use *;
use Validate;
use Deserialize;
This will expect JSON keys firstName and emailAddress.
OpenAPI / utoipa integration
When the openapi feature is enabled on vld, the derive macro also generates
json_schema() and to_openapi_document() methods. This makes #[derive(Validate)]
fully compatible with impl_to_schema! from vld-utoipa:
[]
= { = "0.1", = ["derive", "openapi"] }
= "0.1"
= "5"
use Validate;
use impl_to_schema;
impl_to_schema!;
// Now UpdateLocationRequest implements utoipa::ToSchema
// with camelCase property names in the OpenAPI spec.
Examples
See the playground example for a complete usage demo, including #[derive(Validate)]:
License
MIT