Skip to content

Commit 06ef0b9

Browse files
authored
Open API integration (#159)
* open api integration experimental * experimental response/request inference * improved naming, openapi configuration DX etc * impl open api tags and docs; fixed type in known_headers * small fixes * openapi fixes * refactored to separate crate * added unit tests * added additional unit tests for open api * additional coverage * fixed comments * updated deps; several fixes * more stability fixes * fixed unit test * removed default JSON body for all methods that supports body * path params updates * fixed operationId name in json; cache_control reset for no_store * fixed response reseting and rebind edge cases * fixed issue with empty route; added normalization for paths in router to make it consistent with open api * track RouteGroup routes and warn on late open_api; escape spec metadata before embedding in UI script; normalize path before OpenAPI endpoint exclusion; register prior routes when enabling OpenAPI * refactor(openapi): avoid route config clones and shrink RouteKey allocations; flush pending routes for setting OpenApiConfig * fix(openapi): refresh route metadata on remap * Escaped OpenAPI UI title HTML to prevent injection in <title>; Replayed all stored route configs when replacing the OpenAPI registry (with_open_api / set_open_api) - prevents docs loss when reconfiguring OpenAPI after routes were already mapped * fixed duplicate spec name/path validation (silent collisions) * rebind_route now prunes unreferenced components.schemas after rebinding operations * CDN/SRI hardening for Swagger UI assets
1 parent 311555f commit 06ef0b9

File tree

42 files changed

+4165
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4165
-57
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ jobs:
5757
publish volga-di/Cargo.toml
5858
publish volga-dev-cert/Cargo.toml
5959
publish volga-rate-limiter/Cargo.toml
60+
publish volga-open-api/Cargo.toml
6061
publish volga/Cargo.toml

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Fast, simple, and high-performance web framework for Rust, built on top of
55
Volga is designed to make building HTTP services straightforward and explicit,
66
while keeping performance predictable and overhead minimal.
77

8-
[![latest](https://img.shields.io/badge/latest-0.8.3-blue)](https://crates.io/crates/volga)
8+
[![latest](https://img.shields.io/badge/latest-0.8.4-blue)](https://crates.io/crates/volga)
99
[![latest](https://img.shields.io/badge/rustc-1.90+-964B00)](https://crates.io/crates/volga)
1010
[![License: MIT](https://img.shields.io/badge/License-MIT-violet.svg)](https://github.com/RomanEmreis/volga/blob/main/LICENSE)
1111
[![Build](https://github.com/RomanEmreis/volga/actions/workflows/rust.yml/badge.svg)](https://github.com/RomanEmreis/volga/actions/workflows/rust.yml)
@@ -46,7 +46,7 @@ Volga is a good fit if you:
4646
### Dependencies
4747
```toml
4848
[dependencies]
49-
volga = "0.8.3"
49+
volga = "0.8.4"
5050
tokio = { version = "1", features = ["full"] }
5151
```
5252
### Simple request handler

examples/open_api/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "open_api"
3+
version = "0.1.0"
4+
edition = "2024"
5+
publish = false
6+
7+
[dependencies]
8+
volga = { path = "../../volga", features = ["openapi", "multipart"] }
9+
serde = { version = "1.0.219", features = ["serde_derive"] }
10+
tokio = "1.49.0"
11+
12+
[lints]
13+
workspace = true

examples/open_api/src/main.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//! Run with:
2+
//!
3+
//! ```no_rust
4+
//! cargo run -p open_api
5+
//! ```
6+
7+
use volga::{
8+
App,
9+
Json,
10+
Path,
11+
NamedPath,
12+
Form,
13+
Query,
14+
File,
15+
Multipart,
16+
http::sse::Message,
17+
ok,
18+
sse_stream
19+
};
20+
21+
#[tokio::main]
22+
async fn main() -> std::io::Result<()> {
23+
let mut app = App::new()
24+
.with_open_api(|config| config
25+
.with_title("Open API Demo")
26+
.with_description("Demonstration of Open API with Volga")
27+
.with_version("1.0.0")
28+
.with_specs(["v1", "v2"])
29+
.with_ui());
30+
31+
app.use_open_api();
32+
33+
app.group("/path", |api| {
34+
api.open_api(|cfg| cfg.with_docs(["v1", "v2"]));
35+
36+
api.map_get("/hello", async || "Hello, World!");
37+
api.map_get("/{name}", async |name: String| ok!(fmt: "Hello {name}"));
38+
api.map_get("/{name}/{age:integer}", async |Path((_name, _age)): Path<(String, u32)>| {});
39+
api.map_get("/named/{name}/{age}", async |path: NamedPath<Payload>| ok!(path.into_inner()))
40+
.open_api(|cfg| cfg.produces_json::<Payload>());
41+
});
42+
43+
app.group("/file", |api| {
44+
api.open_api(|cfg| cfg.with_docs(["v1", "v2"]));
45+
46+
api.map_post("/file", async |file: File| file.into_byte_stream());
47+
api.map_post("/multipart", async |mut files: Multipart| sse_stream! {
48+
while let Ok(Some(field)) = files.next_field().await {
49+
yield Message::new().data(field.name().unwrap());
50+
}
51+
});
52+
});
53+
54+
app.map_head("/head", async || {})
55+
.open_api(|cfg| cfg.with_docs(["v1"]));
56+
57+
app.map_get("/query", async |q: Query<Payload>| ok!(fmt: "Hello {}", q.name))
58+
.open_api(|cfg| cfg.with_docs(["v1", "v2"]));
59+
60+
app.map_put("/form", async |payload: Form<Payload>| payload)
61+
.open_api(|cfg| cfg
62+
.with_doc("v2")
63+
.produces_form::<Payload>());
64+
65+
app.map_post("/json", async |payload: Json<Payload>| payload)
66+
.open_api(|cfg| cfg
67+
.with_doc("v2")
68+
.produces_json_example(Payload { name: "John".into(), age: 30 }));
69+
70+
app.run().await
71+
}
72+
73+
#[derive(Default, serde::Deserialize, serde::Serialize)]
74+
struct Payload {
75+
name: String,
76+
age: u64
77+
}

volga-dev-cert/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "volga-dev-cert"
3-
version = "0.8.3"
3+
version = "0.8.4"
44
readme = "README.md"
55
description = "A Rust library for generating self-signed TLS certificates for local development."
66
edition.workspace = true

volga-dev-cert/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
# Volga Development Certificates
22
A Rust library for generating self-signed TLS certificates for local development.
33

4-
[![latest](https://img.shields.io/badge/latest-0.8.3-blue)](https://crates.io/crates/volga)
4+
[![latest](https://img.shields.io/badge/latest-0.8.4-blue)](https://crates.io/crates/volga)
55
[![latest](https://img.shields.io/badge/rustc-1.90+-964B00)](https://crates.io/crates/volga)
66
[![License: MIT](https://img.shields.io/badge/License-MIT-violet.svg)](https://github.com/RomanEmreis/volga/blob/main/LICENSE)
77
[![Build](https://github.com/RomanEmreis/volga/actions/workflows/rust.yml/badge.svg)](https://github.com/RomanEmreis/volga/actions/workflows/rust.yml)
88
[![Release](https://github.com/RomanEmreis/volga/actions/workflows/release.yml/badge.svg)](https://github.com/RomanEmreis/volga/actions/workflows/release.yml)
99

1010
> 💡 **Status**: Volga is currently in preview.
1111
> The public API may change while core abstractions are being finalized.
12+
13+
## License
14+
Volga is licensed under the MIT License. Contributions welcome!

volga-di/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "volga-di"
3-
version = "0.8.3"
3+
version = "0.8.4"
44
readme = "README.md"
55
description = "Dependency Injection tools for Volga Web Framework"
66
edition.workspace = true

volga-di/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Volga DI
22
A standalone, flexible, and easy-to-configure DI container.
33

4-
[![latest](https://img.shields.io/badge/latest-0.8.3-blue)](https://crates.io/crates/volga)
4+
[![latest](https://img.shields.io/badge/latest-0.8.4-blue)](https://crates.io/crates/volga)
55
[![latest](https://img.shields.io/badge/rustc-1.90+-964B00)](https://crates.io/crates/volga)
66
[![License: MIT](https://img.shields.io/badge/License-MIT-violet.svg)](https://github.com/RomanEmreis/volga/blob/main/LICENSE)
77
[![Build](https://github.com/RomanEmreis/volga/actions/workflows/rust.yml/badge.svg)](https://github.com/RomanEmreis/volga/actions/workflows/rust.yml)
@@ -15,12 +15,12 @@ A standalone, flexible, and easy-to-configure DI container.
1515
#### Standalone
1616
```toml
1717
[dependencies]
18-
volga-di = "0.8.3"
18+
volga-di = "..."
1919
```
2020
#### Part of Volga Web Framework
2121
```toml
2222
[dependencies]
23-
volga = { version = "0.8.3", features = ["di"] }
23+
volga = { version = "...", features = ["di"] }
2424
```
2525

2626
### Example
@@ -48,3 +48,6 @@ fn main() {
4848
}
4949
```
5050

51+
## License
52+
Volga is licensed under the MIT License. Contributions welcome!
53+

volga-macros/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "volga-macros"
3-
version = "0.8.3"
3+
version = "0.8.4"
44
readme = "README.md"
55
description = "Macros for Volga Web Framework"
66
edition.workspace = true
@@ -18,7 +18,7 @@ proc-macro = true
1818

1919
[dependencies]
2020
quote = "1.0.44"
21-
syn = { version = "2.0.114", features = ["full"] }
21+
syn = { version = "2.0.117", features = ["full"] }
2222
proc-macro2 = "1.0.106"
2323

2424
[features]

volga-macros/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Volga Macros
22
Macros library for Volga Web Framework
33

4-
[![latest](https://img.shields.io/badge/latest-0.8.3-blue)](https://crates.io/crates/volga)
4+
[![latest](https://img.shields.io/badge/latest-0.8.4-blue)](https://crates.io/crates/volga)
55
[![latest](https://img.shields.io/badge/rustc-1.90+-964B00)](https://crates.io/crates/volga)
66
[![License: MIT](https://img.shields.io/badge/License-MIT-violet.svg)](https://github.com/RomanEmreis/volga/blob/main/LICENSE)
77
[![Build](https://github.com/RomanEmreis/volga/actions/workflows/rust.yml/badge.svg)](https://github.com/RomanEmreis/volga/actions/workflows/rust.yml)
@@ -13,6 +13,9 @@ Macros library for Volga Web Framework
1313
## Dependencies
1414
```toml
1515
[dependencies]
16-
volga = { version = "0.8.3", features = ["macros"] }
16+
volga = { version = "...", features = ["macros"] }
1717
```
1818

19+
## License
20+
Volga is licensed under the MIT License. Contributions welcome!
21+

0 commit comments

Comments
 (0)