Vespera
A fully automated OpenAPI engine for Axum with zero-config route and schema discovery.
Introduction
Vespera is a fully automated OpenAPI engine for Axum — delivering a FastAPI-like developer experience to the Rust ecosystem.
It automatically discovers routes, imports handlers and schemas, and generates a complete OpenAPI 3.1 specification with zero configuration.
Just write your Axum API.
Vespera handles the rest.
Features
1. Zero-Config Route Discovery
Automatically scans Axum routers and submodules to detect all registered routes.
2. Auto-Import of Handlers and Schemas
Automatically pulls in handlers, request/response types, and data models into the OpenAPI spec.
3. Fully Automated OpenAPI Engine
Generates a complete OpenAPI 3.1 document from:
- Routes
- Extractors
- Parameters
- Request bodies
- Response bodies
- Rust data structures (Serde)
4. Type-Safe Schema Extraction
Rust types are converted into JSON Schema with full type fidelity.
5. Built-in Swagger UI
Automatically generates and serves Swagger UI documentation when docs_url is specified, providing interactive API exploration.
6. Axum-First Design
Built specifically for Axum's architecture while offering the productivity of modern API frameworks.
Example
Routes Auto Import
use ;
use vespera;
use Json;
async
async
async
Installation
Add the following to your Cargo.toml:
[]
= "0.1.0"
= "0.8"
= { = "1", = ["full"] }
= { = "1", = ["derive"] }
Quick Start
1. Create Project Structure
Create a src/routes folder in your project root and write route handlers:
src/
├── main.rs
└── routes/
├── mod.rs
├── users.rs
└── posts.rs
2. Write Route Handlers
src/routes/users.rs:
use ;
use ;
/// `/users/{id}` - default method is get
pub async
/// /users
pub async
3. Register Modules
src/routes/mod.rs:
4. Setup Main Application
src/main.rs:
use vespera;
async
Usage
vespera! Macro
Automatically scans routes and generates an Axum Router with optional OpenAPI and Swagger UI support.
// Basic usage: scans "routes" folder
let app = vespera!;
// Specify a custom folder
let app = vespera!;
// With OpenAPI JSON file generation
let app = vespera!;
// Generate multiple OpenAPI JSON files at once
let app = vespera!;
// With OpenAPI and Swagger UI
let app = vespera!;
// Full configuration with all parameters
let app = vespera!;
Parameter Description
-
dir: Route folder name (default:"routes")- You can also specify it directly as a string literal:
vespera!("api")
- You can also specify it directly as a string literal:
-
openapi: OpenAPI JSON file path(s) (optional)- Accepts a single string or an array of strings
- If specified, an OpenAPI 3.1 spec is generated at compile time and writes an
openapi.jsonfile to the specified path (or paths) - Example:
openapi = "openapi.json"→ createsopenapi.jsonfile in project root - Example:
openapi = "docs/api.json"→ createsdocs/api.jsonfile - Example:
openapi = ["openapi.json", "docs/admin.json"]→ writes both files
-
title: API title (optional, default:"API")- Used in the
info.titlefield of the OpenAPI document
- Used in the
-
version: API version (optional, default:"1.0.0")- Used in the
info.versionfield of the OpenAPI document
- Used in the
-
docs_url: Swagger UI documentation URL (optional)- If specified, you can view the API documentation through Swagger UI at that path
- Example: Setting
docs_url = "/docs"allows viewing documentation athttp://localhost:3000/docs
#[route] Attribute Macro
Specify HTTP method and path for handler functions.
// GET request
pub async
// POST request (custom path)
pub async
// Path parameter support
pub async
Tags and Description
You can add tags and descriptions to your routes for better OpenAPI documentation organization.
Tags
Use the tags parameter to group your routes in the OpenAPI documentation:
pub async
pub async
Description
There are two ways to add descriptions to your routes:
1. Using doc comments (recommended):
Doc comments (///) are automatically extracted and used as the route description in OpenAPI:
/// Get all users from the database
///
/// Returns a list of all registered users.
pub async
2. Using the description parameter:
You can also explicitly set the description using the description parameter. This takes priority over doc comments:
/// This doc comment will be ignored
pub async
Combined Example
/// Get user by ID
///
/// Retrieves a specific user by their unique identifier.
pub async
pub async
Supported HTTP Methods
GETPOSTPUTPATCHDELETEHEADOPTIONS
OpenAPI JSON Generation and Swagger UI
When you specify the openapi parameter in the vespera! macro, an OpenAPI 3.1 spec is automatically generated at compile time and writes a file to the specified path.
let app = vespera!;
With this configuration:
- An OpenAPI JSON file is automatically generated at the specified path during compilation
openapi = "openapi.json"→ createsopenapi.jsonfile in project rootopenapi = "docs/api.json"→ createsdocs/api.jsonfile
- If you specify
docs_url, you can view the API documentation through Swagger UI at that path - The OpenAPI spec is automatically generated by analyzing routes, handlers, and request/response types
Note: The build.rs file is no longer needed. The vespera! macro automatically handles it at compile time.
File Structure and Route Mapping
File structure is automatically converted to URL paths:
routes/
├── users.rs → /users
├── posts.rs → /posts
└── admin/
└── users.rs → /admin/users
Project Structure
vespera/
├── Cargo.toml
├── README.md
└── crates/
└── vespera/
├── Cargo.toml
└── src/
├── lib.rs # Main macro definitions
├── args.rs # Macro argument parsing
├── file_utils.rs # File system utilities
├── method.rs # HTTP method definitions
└── route/
├── mod.rs
└── utils.rs # Route information extraction
How It Works
-
Compile-Time Scanning: The
vespera!macro scans the specified folder to discover all route handlers. -
Attribute Parsing: Extracts HTTP method and path information from each handler's
#[route]attribute. -
Code Generation: Automatically generates Axum Router code based on discovered routes.
-
Type Safety: Leverages Rust's type system to ensure all routes are correctly registered at compile time.
Contributing
Contributions are welcome! Please open an issue or submit a Pull Request.
Development Setup
# Clone the repository
# Build
# Run tests
License
This project is licensed under the Apache 2.0 License. See the LICENSE file for details.
Roadmap
- Automatic routes importing
- Automatic OpenAPI 3.1 spec generation (via
vespera!macro) - Automatic request/response schema extraction
- Swagger UI integration
- Support for more Axum extractors
Acknowledgments
Vespera is inspired by FastAPI’s developer experience and also takes inspiration from Next.js, all designed for the Rust ecosystem.