1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Generate typed Rust traits from `OpenAPI` specifications.
//!
//! This crate exposes the [`axum`] attribute macro, which reads an
//! `OpenAPI` specification file at compile time and generates inside the
//! annotated `mod`:
//!
//! - Rust structs for every schema defined in `components/schemas`
//! - A `{OperationId}Request` struct per operation that bundles all parameters
//! and the request body
//! - A `{OperationId}Response` enum per operation whose variants map to HTTP
//! status codes
//! - `impl axum::response::IntoResponse` for every response enum
//! - A `{Title}Api` trait with one `async fn` per operation, keyed by
//! `operationId`
//! - A `router` method on the trait that wires all operations to an
//! [`axum::Router`](https://docs.rs/axum/latest/axum/struct.Router.html)
//!
//! # Quick start
//!
//! ```rust,ignore
//! #[openapi_trait::axum("openapi/petstore.yaml")]
//! pub mod petstore {}
//!
//! #[derive(Clone)]
//! struct MyServer;
//!
//! impl petstore::PetstoreApi for MyServer {
//! type Error = std::convert::Infallible;
//!
//! async fn list_pets(
//! &self,
//! req: petstore::ListPetsRequest,
//! state: axum::extract::State<()>,
//! headers: axum::http::HeaderMap,
//! ) -> Result<petstore::ListPetsResponse, Self::Error> {
//! Ok(petstore::ListPetsResponse::Status200(vec![]))
//! }
//! }
//!
//! // Wire up an axum router.
//! let app = MyServer.router().with_state(());
//! ```
//!
//! See the [`axum`] macro documentation for the full list of generated items
//! and compile-time error conditions.
/// The `openapi_trait` attribute macro, wired to the axum backend.
///
/// Re-exported from [`openapi_trait_axum`]. Apply it to a `mod` block with a
/// path to an `OpenAPI` YAML or JSON file. The path is resolved relative to
/// `CARGO_MANIFEST_DIR`.
pub use openapi_trait as axum;