vld_openapi/schemars1.rs
1//! schemars `>=1, <2`: a two-way bridge between `vld` and `schemars`.
2//!
3//! - **vld → schemars**: [`impl_json_schema!`] implements `schemars::JsonSchema`
4//! from a vld type's `json_schema()`; nested `vld::nested!` types are added to
5//! the generator's definitions, with `$ref`s pointing at its definitions
6//! path, and an OpenAPI 3.0 generator gets OpenAPI 3.0 schemas.
7//! - **schemars → vld**: [`impl_vld_parse!`] validates a `schemars::JsonSchema`
8//! type against its schema ([`validate_with_schema`]) and implements
9//! `vld::schema::VldParse`, so it works with vld extractors.
10//!
11//! The selected schemars is re-exported as [`schemars`]; the
12//! version-independent items of [`crate::validator`] are re-exported here.
13//!
14//! **aide**: aide generates OpenAPI from `schemars::JsonSchema`, so
15//! `impl_json_schema!` makes a vld type usable in `aide::axum::Json<T>` and
16//! friends (nested types land under aide's `#/components/schemas/`). Pick the
17//! module of the schemars major your aide uses (`cargo tree -i schemars`):
18//! aide 0.16 builds on schemars 1: aide 0.16 users use this module.
19//!
20//! ```rust
21//! use vld_openapi::schemars1::prelude::*;
22//! use vld_openapi::schemars1::schemars;
23#![doc = include_str!("schemars/doctest.rs")]
24//! ```
25//!
26//! Guide: <https://s00d.github.io/vld/integrations/openapi/schemars>
27
28pub use ::schemars1 as schemars;
29pub use ::vld;
30
31// Each major compiles the shared implementation against its own alias.
32#[allow(clippy::duplicate_mod)]
33#[path = "schemars/shared.rs"]
34mod shared;
35pub use shared::*;
36
37/// Implement `schemars::JsonSchema` for a type with a `json_schema()`
38/// associated function (`vld::schema!`, `#[derive(Validate)]`):
39/// `impl_json_schema!(T)` or `impl_json_schema!(T, "SchemaName")`. See the
40/// [module docs](self).
41#[doc(hidden)]
42#[macro_export]
43macro_rules! __schemars1_impl_json_schema {
44 ($($t:tt)*) => { $crate::__schemars_impl_json_schema!(schemars1; $($t)*); };
45}
46#[doc(inline)]
47pub use crate::__schemars1_impl_json_schema as impl_json_schema;
48
49/// Implement `vld::schema::VldParse` and [`SchemarsValidate`] for a type that
50/// derives `schemars::JsonSchema`, `serde::Serialize` and `serde::Deserialize`:
51/// `impl_vld_parse!(T)`. The value is validated against the type's schemars
52/// schema, then deserialized. See the [module docs](self).
53#[doc(hidden)]
54#[macro_export]
55macro_rules! __schemars1_impl_vld_parse {
56 ($($t:tt)*) => { $crate::__schemars_impl_vld_parse!(schemars1; $($t)*); };
57}
58#[doc(inline)]
59pub use crate::__schemars1_impl_vld_parse as impl_vld_parse;