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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//! Procedural macros for fastapi_rust.
//!
//! This crate provides the following macros:
//!
//! - Route macros: `#[get]`, `#[post]`, `#[put]`, `#[delete]`, `#[patch]`, `#[head]`, `#[options]`
//! - `#[derive(Validate)]` for compile-time validation
//! - `#[derive(JsonSchema)]` for OpenAPI schema generation
//!
//! # Role In The System
//!
//! `fastapi-macros` is the compile-time glue that keeps the runtime minimal.
//! It analyzes handler signatures, generates route registration metadata, and
//! enforces validation/schema rules without any runtime reflection. The emitted
//! code targets types from `fastapi-core` and `fastapi-openapi`, and is re-exported
//! by the `fastapi` facade crate for user ergonomics.
//!
//! # Example
//!
//! ```ignore
//! use fastapi::prelude::*;
//!
//! #[get("/items/{id}")]
//! async fn get_item(cx: &Cx, id: Path<i64>) -> Json<Item> {
//! // ...
//! }
//! ```
use TokenStream;
/// Mark a function as a GET handler.
///
/// # Example
///
/// ```ignore
/// #[get("/items")]
/// async fn list_items() -> Json<Vec<Item>> {
/// // ...
/// }
/// ```
/// Mark a function as a POST handler.
/// Mark a function as a PUT handler.
/// Mark a function as a DELETE handler.
/// Mark a function as a PATCH handler.
/// Mark a function as a HEAD handler.
///
/// HEAD requests are identical to GET but return only headers, not body.
/// Useful for checking resource existence or metadata without full content.
///
/// # Example
///
/// ```ignore
/// #[head("/items/{id}")]
/// async fn head_item(id: Path<i64>) -> StatusCode {
/// StatusCode::OK
/// }
/// ```
/// Mark a function as an OPTIONS handler.
///
/// OPTIONS requests return allowed methods and CORS headers for a resource.
///
/// # Example
///
/// ```ignore
/// #[options("/items")]
/// async fn options_items() -> Response {
/// Response::builder()
/// .header("Allow", "GET, POST, OPTIONS")
/// .body(())
/// }
/// ```
/// Derive validation for a struct.
///
/// # Validation Attributes
///
/// - `#[validate(length(min = 1, max = 100))]` - String length
/// - `#[validate(range(min = 0.0, max = 1.0))]` - Numeric range
/// - `#[validate(email)]` - Email format
/// - `#[validate(regex = "pattern")]` - Regex pattern
///
/// # Example
///
/// ```ignore
/// #[derive(Validate)]
/// struct CreateUser {
/// #[validate(length(min = 1, max = 50))]
/// name: String,
/// #[validate(email)]
/// email: String,
/// }
/// ```
/// Derive JSON Schema for OpenAPI.
///
/// # Example
///
/// ```ignore
/// #[derive(JsonSchema)]
/// struct Item {
/// id: i64,
/// name: String,
/// #[schema(nullable)]
/// description: Option<String>,
/// }
/// ```
/// Derive response model alias metadata for FastAPI-compatible `by_alias` handling.
///
/// This emits an implementation of `fastapi_core::ResponseModelAliases` using
/// `#[serde(rename = ...)]` and `#[serde(rename_all = ...)]` attributes.