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//! | [`validator`] | always | validate JSON against a JSON Schema, inspect and combine schemas, `to_openapi3` |
12//!
13//! ```toml
14//! vld-openapi = { version = "0.8", features = ["utoipa-5"] }
15//! ```
16//!
17//! ```rust
18//! let schema = serde_json::json!({"type": "string", "minLength": 2});
19//! assert!(vld_openapi::validator::validate_with_schema(&schema, &"hi".into()).is_ok());
20//! assert!(vld_openapi::validator::validate_with_schema(&schema, &"h".into()).is_err());
21//! ```
22//!
23//! Guide: <https://s00d.github.io/vld/integrations/openapi/utoipa>
24#![cfg_attr(docsrs, feature(doc_cfg))]
25#![warn(missing_docs)]
26
27pub use vld;
28
29mod macros;
30
31pub mod validator;
32
33#[cfg(feature = "schemars-0")]
34#[cfg_attr(docsrs, doc(cfg(feature = "schemars-0")))]
35pub mod schemars0;
36#[cfg(feature = "schemars-1")]
37#[cfg_attr(docsrs, doc(cfg(feature = "schemars-1")))]
38pub mod schemars1;
39#[cfg(feature = "utoipa-5")]
40#[cfg_attr(docsrs, doc(cfg(feature = "utoipa-5")))]
41pub mod utoipa5;
42#[cfg(feature = "utoipa-6")]
43#[cfg_attr(docsrs, doc(cfg(feature = "utoipa-6")))]
44pub mod utoipa6;
45
46/// Fallback for types without nested vld schemas: the inherent
47/// `__vld_nested_schemas` of `vld::schema!` / derive types wins over this
48/// trait method in `<T>::f()` path resolution.
49#[doc(hidden)]
50pub trait __VldNestedSchemasFallback {
51 fn __vld_nested_schemas() -> Vec<vld::openapi::NestedSchemaEntry> {
52 Vec::new()
53 }
54}
55
56impl<T: ?Sized> __VldNestedSchemasFallback for T {}