Skip to main content

vld_openapi/
utoipa6.rs

1//! utoipa 6: `vld` schemas as utoipa OpenAPI types.
2//!
3//! [`impl_to_schema!`] implements utoipa's `PartialSchema`, `ToSchema` and
4//! `IntoParams` from the vld `json_schema()` of a `vld::schema!` or
5//! `#[derive(Validate)]` type, so validation rules and OpenAPI docs come from
6//! one definition. Nested `vld::nested!` types are registered as components
7//! automatically. [`json_schema_to_schema`] converts any JSON Schema value.
8//! utoipa 6 is re-exported as [`utoipa`].
9//!
10//! Mark parameter structs with utoipa's `#[into_params(parameter_in = Query)]`
11//! (or `Path`, `Header`, `Cookie`), or pass the location to the macro:
12//! `impl_to_schema!(T, query)`. `impl_to_schema!(T, "Name")` sets the
13//! component name.
14//!
15//! ```rust
16//! use vld_openapi::utoipa6::prelude::*;
17//! use vld_openapi::utoipa6::utoipa;
18#![doc = include_str!("utoipa/doctest.rs")]
19//! ```
20//!
21//! Guide: <https://s00d.github.io/vld/integrations/openapi/utoipa>
22
23pub use ::utoipa6 as utoipa;
24
25// Each major compiles the shared implementation against its own alias.
26#[allow(clippy::duplicate_mod)]
27#[path = "utoipa/shared.rs"]
28mod shared;
29pub use shared::*;
30
31/// Bridge a vld type to utoipa `ToSchema` + `IntoParams`: `impl_to_schema!(T)`,
32/// `impl_to_schema!(T, "ComponentName")`, or `impl_to_schema!(T, query)`
33/// (`path`, `header`, `cookie`) to force the parameter location. See the
34/// [module docs](self).
35#[doc(hidden)]
36#[macro_export]
37macro_rules! __utoipa6_impl_to_schema {
38    ($($t:tt)*) => { $crate::__utoipa_impl_to_schema!(utoipa6; $($t)*); };
39}
40#[doc(inline)]
41pub use crate::__utoipa6_impl_to_schema as impl_to_schema;