vld_openapi/lib.rs
1//! # vld-openapi — `vld` schemas in OpenAPI tools
2//!
3//! One module per integration, each behind its feature (none is on by
4//! default). The majors of one dependency are additive: any set of features
5//! compiles together.
6//!
7//! | module | feature | what it does |
8//! |---|---|---|
9//! | [`utoipa5`] / [`utoipa6`] | `utoipa-5` / `utoipa-6` | `impl_to_schema!`: utoipa `ToSchema` / `IntoParams` from a vld type |
10//! | [`schemars0`] / [`schemars1`] | `schemars-0` / `schemars-1` | `impl_json_schema!` (vld → `schemars::JsonSchema`, also for aide) and `impl_vld_parse!` (schemars type → vld validation) |
11//! | [`poem_openapi`] | `poem-openapi` | `impl_type!`: poem-openapi `Type` / `ParseFromJSON` from a vld type; `VldJson<T>` request body answering 422 with every issue |
12//! | [`validator`] | always | validate JSON against a JSON Schema, inspect and combine schemas, `to_openapi3` |
13//!
14//! ```toml
15//! vld-openapi = { version = "0.8", features = ["utoipa-5"] }
16//! ```
17//!
18//! ```rust
19//! let schema = serde_json::json!({"type": "string", "minLength": 2});
20//! assert!(vld_openapi::validator::validate_with_schema(&schema, &"hi".into()).is_ok());
21//! assert!(vld_openapi::validator::validate_with_schema(&schema, &"h".into()).is_err());
22//! ```
23//!
24//! Guide: <https://s00d.github.io/vld/integrations/openapi/utoipa>
25#![cfg_attr(docsrs, feature(doc_cfg))]
26#![warn(missing_docs)]
27
28pub use vld;
29
30mod macros;
31
32pub mod validator;
33
34#[cfg(feature = "poem-openapi")]
35#[cfg_attr(docsrs, doc(cfg(feature = "poem-openapi")))]
36pub mod poem_openapi;
37#[cfg(feature = "schemars-0")]
38#[cfg_attr(docsrs, doc(cfg(feature = "schemars-0")))]
39pub mod schemars0;
40#[cfg(feature = "schemars-1")]
41#[cfg_attr(docsrs, doc(cfg(feature = "schemars-1")))]
42pub mod schemars1;
43#[cfg(feature = "utoipa-5")]
44#[cfg_attr(docsrs, doc(cfg(feature = "utoipa-5")))]
45pub mod utoipa5;
46#[cfg(feature = "utoipa-6")]
47#[cfg_attr(docsrs, doc(cfg(feature = "utoipa-6")))]
48pub mod utoipa6;
49
50/// Fallback for types without nested vld schemas: the inherent
51/// `__vld_nested_schemas` of `vld::schema!` / derive types wins over this
52/// trait method in `<T>::f()` path resolution.
53#[doc(hidden)]
54pub trait __VldNestedSchemasFallback {
55 fn __vld_nested_schemas() -> Vec<vld::openapi::NestedSchemaEntry> {
56 Vec::new()
57 }
58}
59
60impl<T: ?Sized> __VldNestedSchemasFallback for T {}