Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .changepacks/changepack_log_KcdLl0PBqSzwXJah8jSDB.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"changes":{"crates/vespera_core/Cargo.toml":"Patch","crates/vespera_macro/Cargo.toml":"Patch","crates/vespera/Cargo.toml":"Patch"},"note":"Apply automatic sync to Cargo.toml package version","date":"2026-01-04T08:11:58.130989600Z"}
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ let app = vespera!(
dir = "routes", // Route folder name (default: "routes")
openapi = "openapi.json", // OpenAPI JSON file path (optional)
title = "My API", // API title (optional, default: "API")
version = "1.0.0", // API version (optional, default: "1.0.0")
version = "1.0.0", // API version (optional, default: Cargo.toml version)
docs_url = "/docs" // Swagger UI documentation URL (optional)
);
```
Expand All @@ -268,13 +268,53 @@ let app = vespera!(
- **`title`**: API title (optional, default: `"API"`)
- Used in the `info.title` field of the OpenAPI document

- **`version`**: API version (optional, default: `"1.0.0"`)
- **`version`**: API version (optional, default: your `Cargo.toml` version)
- Used in the `info.version` field of the OpenAPI document
- If not specified, automatically uses the version from your project's `Cargo.toml` (`CARGO_PKG_VERSION`)

- **`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 at `http://localhost:3000/docs`

- **`redoc_url`**: ReDoc documentation URL (optional)
- If specified, you can view the API documentation through ReDoc at that path
- Example: Setting `redoc_url = "/redoc"` allows viewing documentation at `http://localhost:3000/redoc`

#### Environment Variables

All macro parameters can also be configured via environment variables. Environment variables are used as fallbacks when the corresponding macro parameter is not specified.

| Macro Parameter | Environment Variable | Description |
|-----------------|---------------------|-------------|
| `dir` | `VESPERA_DIR` | Route folder name |
| `openapi` | `VESPERA_OPENAPI` | OpenAPI JSON file path |
| `title` | `VESPERA_TITLE` | API title |
| `version` | `VESPERA_VERSION` | API version |
| `docs_url` | `VESPERA_DOCS_URL` | Swagger UI documentation URL |
| `redoc_url` | `VESPERA_REDOC_URL` | ReDoc documentation URL |

**Priority Order** (highest to lowest):
1. Macro parameter (e.g., `version = "1.0.0"`)
2. Environment variable (e.g., `VESPERA_VERSION`)
3. `CARGO_PKG_VERSION` (for `version` only)
4. Default value

**Example:**

```bash
# Set environment variables
export VESPERA_TITLE="My Production API"
export VESPERA_VERSION="2.0.0"
export VESPERA_DOCS_URL="/api-docs"
```

```rust
// These will use the environment variables as defaults
let app = vespera!(
openapi = "openapi.json"
);
```

### `#[route]` Attribute Macro

Specify HTTP method and path for handler functions.
Expand Down
16 changes: 11 additions & 5 deletions crates/vespera_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,17 @@ impl Parse for AutoRouterInput {
.map(|f| LitStr::new(&f, Span::call_site()))
.ok()
}),
version: version.or_else(|| {
std::env::var("VESPERA_VERSION")
.map(|f| LitStr::new(&f, Span::call_site()))
.ok()
}),
version: version
.or_else(|| {
std::env::var("VESPERA_VERSION")
.map(|f| LitStr::new(&f, Span::call_site()))
.ok()
})
.or_else(|| {
std::env::var("CARGO_PKG_VERSION")
.map(|f| LitStr::new(&f, Span::call_site()))
.ok()
}),
docs_url: docs_url.or_else(|| {
std::env::var("VESPERA_DOCS_URL")
.map(|f| LitStr::new(&f, Span::call_site()))
Expand Down
2 changes: 1 addition & 1 deletion examples/axum-example/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.1.0",
"info": {
"title": "API",
"version": "1.0.0"
"version": "0.1.0"
},
"servers": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ expression: "std::fs::read_to_string(\"openapi.json\").unwrap()"
"openapi": "3.1.0",
"info": {
"title": "API",
"version": "1.0.0"
"version": "0.1.0"
},
"servers": [
{
Expand Down
2 changes: 1 addition & 1 deletion openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.1.0",
"info": {
"title": "API",
"version": "1.0.0"
"version": "0.1.0"
},
"servers": [
{
Expand Down