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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
// SPDX-FileCopyrightText: 2025-2026 RAprogramm <andrey.rozanov.vl@gmail.com>
// SPDX-License-Identifier: MIT
//! API configuration type definitions.
//!
//! This module defines the data structures that hold parsed API configuration
//! from `#[entity(api(...))]` attributes. These types drive code generation
//! for HTTP handlers, OpenAPI documentation, and router setup.
//!
//! # Type Hierarchy
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │ Configuration Types │
//! ├─────────────────────────────────────────────────────────────────┤
//! │ │
//! │ ApiConfig │
//! │ ├─► tag: Option<String> # OpenAPI tag name │
//! │ ├─► tag_description: Option<String> │
//! │ ├─► path_prefix: Option<String> # URL prefix │
//! │ ├─► security: Option<String> # Auth scheme │
//! │ ├─► public_commands: Vec<Ident> # No-auth commands │
//! │ ├─► version: Option<String> # API version │
//! │ ├─► deprecated_in: Option<String> │
//! │ ├─► handlers: HandlerConfig # CRUD settings │
//! │ └─► OpenAPI Info Fields │
//! │ ├─► title, description, api_version │
//! │ ├─► license, license_url │
//! │ └─► contact_name, contact_email, contact_url │
//! │ │
//! │ HandlerConfig │
//! │ ├─► create: bool # POST /collection │
//! │ ├─► get: bool # GET /collection/{id} │
//! │ ├─► update: bool # PATCH /collection/{id} │
//! │ ├─► delete: bool # DELETE /collection/{id} │
//! │ └─► list: bool # GET /collection │
//! │ │
//! └─────────────────────────────────────────────────────────────────┘
//! ```
//!
//! # Handler Configuration
//!
//! The `handlers` field controls which CRUD operations generate handlers:
//!
//! | Syntax | Result |
//! |--------|--------|
//! | `handlers` | All five handlers |
//! | `handlers = true` | All five handlers |
//! | `handlers = false` | No handlers |
//! | `handlers(create, get)` | Only specified handlers |
//!
//! # Security Behavior
//!
//! Security is applied to all handlers unless overridden:
//!
//! ```text
//! security = "bearer" ─────► All handlers require auth
//! │
//! └─► public = [Login] ─────► Login command has no auth
//! ```
//!
//! # Path Construction
//!
//! Paths are built from prefix and version:
//!
//! | prefix | version | Entity | Result |
//! |--------|---------|--------|--------|
//! | - | - | User | `/users` |
//! | `/api` | - | User | `/api/users` |
//! | `/api` | `v1` | User | `/api/v1/users` |
//! | `/api/` | `v1` | User | `/api/v1/users` (trailing slash handled) |
use Ident;
/// Configuration for selective CRUD handler generation.
///
/// Controls which of the five standard CRUD handlers are generated:
/// create, get, update, delete, and list.
///
/// # Syntax Variants
///
/// The `handlers` option in `api(...)` supports three forms:
///
/// ## Flag Form
///
/// ```rust,ignore
/// api(tag = "Users", handlers) // All handlers enabled
/// ```
///
/// ## Boolean Form
///
/// ```rust,ignore
/// api(tag = "Users", handlers = true) // All handlers
/// api(tag = "Users", handlers = false) // No handlers
/// ```
///
/// ## Selective Form
///
/// ```rust,ignore
/// api(tag = "Users", handlers(create, get, list)) // Specific handlers
/// ```
///
/// # HTTP Method Mapping
///
/// | Handler | HTTP Method | Path | Description |
/// |---------|-------------|------|-------------|
/// | `create` | POST | `/entities` | Create new entity |
/// | `get` | GET | `/entities/{id}` | Retrieve by ID |
/// | `update` | PATCH | `/entities/{id}` | Partial update |
/// | `delete` | DELETE | `/entities/{id}` | Remove entity |
/// | `list` | GET | `/entities` | List with pagination |
///
/// # Default Behavior
///
/// All handlers are `false` by default. To generate handlers, you must
/// explicitly enable them via one of the syntax forms above.
/// Complete API configuration parsed from `#[entity(api(...))]`.
///
/// This struct holds all configuration options that control HTTP handler
/// generation and OpenAPI documentation. It is populated by
/// [`parse_api_config`] and consumed by code generation modules.
///
/// # Configuration Categories
///
/// ## Routing Configuration
///
/// | Field | Purpose | Example |
/// |-------|---------|---------|
/// | `tag` | OpenAPI grouping | `"Users"` |
/// | `path_prefix` | URL base path | `"/api"` |
/// | `version` | API version segment | `"v1"` |
///
/// ## Security Configuration
///
/// | Field | Purpose | Example |
/// |-------|---------|---------|
/// | `security` | Default auth scheme | `"bearer"` |
/// | `public_commands` | No-auth commands | `[Login, Register]` |
///
/// ## OpenAPI Info
///
/// | Field | OpenAPI Location |
/// |-------|------------------|
/// | `title` | `info.title` |
/// | `description` | `info.description` |
/// | `api_version` | `info.version` |
/// | `license` | `info.license.name` |
/// | `license_url` | `info.license.url` |
/// | `contact_name` | `info.contact.name` |
/// | `contact_email` | `info.contact.email` |
/// | `contact_url` | `info.contact.url` |
///
/// # Usage in Code Generation
///
/// ```text
/// ApiConfig
/// │
/// ├─► crud/mod.rs ─────────► CRUD handler functions
/// ├─► openapi/mod.rs ──────► OpenAPI struct + modifier
/// └─► router.rs ───────────► Axum Router factory
/// ```
///
/// # Default State
///
/// A default `ApiConfig` has all options set to `None` or empty.
/// Use `is_enabled()` to check if API generation should proceed.