aide/lib.rs
1//! # Aide
2//!
3//! `aide` is a code-first [Open API](https://www.openapis.org/) documentation
4//! generator library. It aims for tight integrations with frameworks and
5//! following their conventions, while tries to be out
6//! of the way when it is not needed.
7//!
8//! The goal is to minimize the learning curve, mental context switches
9//! and make documentation somewhat slightly less of a chore.
10//!
11//! See the [examples](https://github.com/tamasfe/aide/tree/master/examples)
12//! to see how Aide is used with various frameworks.
13//!
14//! Currently only Open API version `3.1.0` is supported.
15//!
16//! Previous releases of aide relied heavily on macros, and the
17//! [`linkme`](https://docs.rs/linkme/latest/linkme/) crate for automagic global state.
18//! While it all worked, macros were hard to reason about,
19//! rustfmt did not work with them, code completion was hit-and-miss.
20//!
21//! With `0.5.0`, aide was rewritten and instead it is based on on good old functions,
22//! type inference and declarative APIs based on the builder pattern.
23//!
24//! Now all documentation can be traced in the source code[^1],
25//! no more macro and global magic all over the place.[^2]
26//!
27//! [^1]: and with [tracing] spans
28//!
29//! [^2]: A thread-local context is still used for some settings and
30//! shared state.
31//!
32//! ## Type-based Generation
33//!
34//! The library uses [`schemars`] for schema generation for types.
35//! It should be enough to slap [`JsonSchema`](schemars::JsonSchema)
36//! alongside [serde]'s `Serialize/Deserialize` for JSON-based APIs.
37//!
38//! Additionally the [`OperationInput`] and [`OperationOutput`] traits
39//! are used for extractor and response types in frameworks to automatically generate
40//! expected HTTP parameter and response documentation.
41//!
42//! For example a `Json<T>` extractor will generate an `application/json`
43//! request body with the schema of `T` if it implements
44//! [`JsonSchema`](schemars::JsonSchema).
45//!
46//! ## Declarative Documentation
47//!
48//! All manual documentation is based on composable [`transform`]
49//! functions and builder-pattern-like API.
50//!
51//! ## Supported Frameworks
52//!
53//! - [axum](https://docs.rs/axum/latest/axum/): [`aide::axum`](axum).
54//! - [actix-web](https://docs.rs/actix-web/latest/actix_web/) is **not
55//! supported** since `0.5.0` only due to lack of developer capacity,
56//! but it's likely to be supported again in the future. If you use
57//! `actix-web` you can still use the macro-based `0.4.*` version of the
58//! library for the time being.
59//!
60//! ## Errors
61//!
62//! Some errors occur during code generation, these
63//! are usually safe to ignore but might indicate bugs.
64//!
65//! By default no action is taken on errors, in order to handle them
66//! it is possible to register an error handler in the thread-local context
67//! with [`aide::generate::on_error`](crate::generate::on_error).
68//!
69//! False positives are chosen over silently swallowing potential
70//! errors, these might happen when there is not enough contextual
71//! information to determine whether an error is in fact an error.
72//! It is important to keep this in mind, without any filters
73//! **simply panicking on all errors is not advised**, especially
74//! not in production.
75//!
76//! ## Feature Flags
77//!
78//! No features are enabled by default.
79//!
80//! - `macros`: additional helper macros
81//!
82//! ### Third-party trait implementations
83//!
84//! - `bytes`
85//! - `http`
86//!
87//! ### axum integration
88//!
89//! `axum` and its features gates:
90//!
91//! - `axum`
92//! - `axum-form`
93//! - `axum-json`
94//! - `axum-matched-path`
95//! - `axum-multipart`
96//! - `axum-original-uri`
97//! - `axum-query`
98//! - `axum-tokio` (for `ConnectInfo`)
99//! - `axum-ws` (WebSockets)
100//!
101//! `axum-extra` and its features gates:
102//!
103//! - `axum-extra`
104//! - `axum-extra-cookie`
105//! - `axum-extra-cookie-private`
106//! - `axum-extra-form`
107//! - `axum-extra-headers`
108//! - `axum-extra-query`
109//! - `axum-extra-json-deserializer`
110//!
111//! ## MSRV
112//!
113//! The library will always support the latest stable Rust version,
114//! it might support older versions but without guarantees.
115//!
116#![cfg_attr(docsrs, feature(doc_cfg))]
117#![warn(clippy::pedantic, missing_docs, unreachable_pub, rust_2018_idioms)]
118#![allow(
119 clippy::default_trait_access,
120 clippy::doc_markdown,
121 clippy::module_name_repetitions,
122 clippy::wildcard_imports,
123 clippy::too_many_lines,
124 clippy::single_match_else,
125 clippy::manual_let_else
126)]
127
128// Required for using macros such as the `OperationIo` derive macro in tests.
129// These macros use paths starting with `aide::` which would otherwise be invalid within this crate.
130#[cfg(test)]
131extern crate self as aide;
132
133#[macro_use]
134mod macros;
135mod impls;
136
137pub mod error;
138pub mod generate;
139pub mod operation;
140
141pub mod openapi;
142pub mod transform;
143pub mod util;
144
145#[cfg(feature = "axum")]
146pub mod axum;
147
148mod helpers;
149#[cfg(feature = "redoc")]
150pub mod redoc;
151
152#[cfg(feature = "swagger")]
153pub mod swagger;
154
155#[cfg(feature = "scalar")]
156pub mod scalar;
157
158pub use helpers::{
159 no_api::NoApi, use_api::IntoApi, use_api::UseApi, with_api::ApiOverride, with_api::WithApi,
160};
161
162pub use error::Error;
163pub use operation::{OperationInput, OperationOutput};
164
165#[cfg(feature = "macros")]
166pub use aide_macros::OperationIo;