Skip to content

Commit 3117cd5

Browse files
authored
Merge pull request #42 from dev-five-git/add-pkg-version
Add pkg version
2 parents 8ea2824 + 0c4c9ee commit 3117cd5

7 files changed

Lines changed: 60 additions & 13 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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"}

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ let app = vespera!(
248248
dir = "routes", // Route folder name (default: "routes")
249249
openapi = "openapi.json", // OpenAPI JSON file path (optional)
250250
title = "My API", // API title (optional, default: "API")
251-
version = "1.0.0", // API version (optional, default: "1.0.0")
251+
version = "1.0.0", // API version (optional, default: Cargo.toml version)
252252
docs_url = "/docs" // Swagger UI documentation URL (optional)
253253
);
254254
```
@@ -268,13 +268,53 @@ let app = vespera!(
268268
- **`title`**: API title (optional, default: `"API"`)
269269
- Used in the `info.title` field of the OpenAPI document
270270

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

274275
- **`docs_url`**: Swagger UI documentation URL (optional)
275276
- If specified, you can view the API documentation through Swagger UI at that path
276277
- Example: Setting `docs_url = "/docs"` allows viewing documentation at `http://localhost:3000/docs`
277278

279+
- **`redoc_url`**: ReDoc documentation URL (optional)
280+
- If specified, you can view the API documentation through ReDoc at that path
281+
- Example: Setting `redoc_url = "/redoc"` allows viewing documentation at `http://localhost:3000/redoc`
282+
283+
#### Environment Variables
284+
285+
All macro parameters can also be configured via environment variables. Environment variables are used as fallbacks when the corresponding macro parameter is not specified.
286+
287+
| Macro Parameter | Environment Variable | Description |
288+
|-----------------|---------------------|-------------|
289+
| `dir` | `VESPERA_DIR` | Route folder name |
290+
| `openapi` | `VESPERA_OPENAPI` | OpenAPI JSON file path |
291+
| `title` | `VESPERA_TITLE` | API title |
292+
| `version` | `VESPERA_VERSION` | API version |
293+
| `docs_url` | `VESPERA_DOCS_URL` | Swagger UI documentation URL |
294+
| `redoc_url` | `VESPERA_REDOC_URL` | ReDoc documentation URL |
295+
296+
**Priority Order** (highest to lowest):
297+
1. Macro parameter (e.g., `version = "1.0.0"`)
298+
2. Environment variable (e.g., `VESPERA_VERSION`)
299+
3. `CARGO_PKG_VERSION` (for `version` only)
300+
4. Default value
301+
302+
**Example:**
303+
304+
```bash
305+
# Set environment variables
306+
export VESPERA_TITLE="My Production API"
307+
export VESPERA_VERSION="2.0.0"
308+
export VESPERA_DOCS_URL="/api-docs"
309+
```
310+
311+
```rust
312+
// These will use the environment variables as defaults
313+
let app = vespera!(
314+
openapi = "openapi.json"
315+
);
316+
```
317+
278318
### `#[route]` Attribute Macro
279319

280320
Specify HTTP method and path for handler functions.

crates/vespera_macro/src/lib.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,17 @@ impl Parse for AutoRouterInput {
175175
.map(|f| LitStr::new(&f, Span::call_site()))
176176
.ok()
177177
}),
178-
version: version.or_else(|| {
179-
std::env::var("VESPERA_VERSION")
180-
.map(|f| LitStr::new(&f, Span::call_site()))
181-
.ok()
182-
}),
178+
version: version
179+
.or_else(|| {
180+
std::env::var("VESPERA_VERSION")
181+
.map(|f| LitStr::new(&f, Span::call_site()))
182+
.ok()
183+
})
184+
.or_else(|| {
185+
std::env::var("CARGO_PKG_VERSION")
186+
.map(|f| LitStr::new(&f, Span::call_site()))
187+
.ok()
188+
}),
183189
docs_url: docs_url.or_else(|| {
184190
std::env::var("VESPERA_DOCS_URL")
185191
.map(|f| LitStr::new(&f, Span::call_site()))

examples/axum-example/openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.1.0",
33
"info": {
44
"title": "API",
5-
"version": "1.0.0"
5+
"version": "0.1.0"
66
},
77
"servers": [
88
{

examples/axum-example/tests/snapshots/integration_test__openapi.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ expression: "std::fs::read_to_string(\"openapi.json\").unwrap()"
66
"openapi": "3.1.0",
77
"info": {
88
"title": "API",
9-
"version": "1.0.0"
9+
"version": "0.1.0"
1010
},
1111
"servers": [
1212
{

openapi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"openapi": "3.1.0",
33
"info": {
44
"title": "API",
5-
"version": "1.0.0"
5+
"version": "0.1.0"
66
},
77
"servers": [
88
{

0 commit comments

Comments
 (0)