Skip to main content

Crate vespera_macro

Crate vespera_macro 

Source
Expand description

Vespera macro implementation crate.

This crate contains all the proc-macros for Vespera:

  • #[vespera::route(...)] - Mark a function as a route handler
  • #[derive(Schema)] - Register a type for OpenAPI schema generation
  • schema!(...) - Get OpenAPI schema at compile time
  • vespera!(...) - Generate Axum router with OpenAPI
  • export_app!(...) - Export router for merging

§Architecture

┌─────────────────────────────────────────────────────────────────┐
│ Compile-time (vespera! macro)                                    │
├─────────────────────────────────────────────────────────────────┤
│ 1. Scan src/routes/ for .rs files              [collector]       │
│ 2. Parse #[route] attributes                   [args, route]     │
│ 3. Extract handler signatures                  [parser]          │
│ 4. Convert Rust types → JSON Schema            [parser/schema]   │
│ 5. Build OpenAPI document                      [openapi_gen]     │
│ 6. Write openapi.json to disk                  [vespera_impl]    │
│ 7. Generate Axum Router TokenStream            [router_codegen]  │
│ 8. Inject Swagger/ReDoc HTML routes           [router_codegen]  │
└─────────────────────────────────────────────────────────────────┘

# Module Organization

- `args` - Parse `#[route(...)]` attribute arguments
- `collector` - Filesystem scanning and route discovery
- `error` - Unified error handling
- `http` - HTTP method constants and validation
- `macro_storage` - Shared per-crate storage for `#[route]` / `#[cron]` metadata
- `metadata` - Type definitions for collected metadata
- `method` - HTTP method token stream generation
- `openapi_generator` - OpenAPI spec assembly
- `parser` - Type extraction and schema generation
- `route` - Route information structures
- `route_impl` - Route attribute macro implementation
- `router_codegen` - Router and macro input parsing
- `schema_impl` - Schema derive macro implementation
- `schema_macro` - `schema_type!` macro implementation
- `vespera_impl` - Main macro orchestration

Macros§

export_app
Export a vespera app as a reusable component.
schema
Generate an OpenAPI Schema from a type with optional field filtering.
schema_type
Generate a new struct type derived from an existing type with field filtering.
vespera

Attribute Macros§

cron
cron attribute macro
route
route attribute macro

Derive Macros§

Multipart
Derive macro for Multipart with serde attribute support.
Schema
Derive macro for Schema