Skip to content

Commit c2e9f45

Browse files
twuebijuhaku
andauthored
fix: avoid cloning ApiDoc on every request for axum (#1393)
--------- Co-authored-by: Juha Kukkonen <juha7kukkonen@gmail.com>
1 parent cecda05 commit c2e9f45

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

utoipa-swagger-ui/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Fixed
6+
7+
* Avoid cloning ApiDoc on every request for axum (https://github.com/juhaku/utoipa/pull/1393)
8+
59
### Changed
610

711
* Update build dependency `zip` to v3.0 (https://github.com/juhaku/utoipa/pull/1391)

utoipa-swagger-ui/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ axum = { version = "0.8.0", default-features = false, features = [
3232
utoipa = { version = "5.0.0", path = "../utoipa", default-features = false, features = [
3333
"macros",
3434
] }
35-
serde = { version = "1.0", features = ["derive"] }
35+
serde = { version = "1.0", features = ["derive", "rc"] }
3636
serde_json = { version = "1.0" }
3737
base64 = { version = "0.22.1" }
3838

utoipa-swagger-ui/src/axum.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ where
2828
Vec::<Url>::with_capacity(urls_capacity + external_urls_capacity),
2929
),
3030
|router_and_urls, (url, openapi)| {
31-
add_api_doc_to_urls(router_and_urls, (url, ApiDoc::Utoipa(openapi)))
31+
add_api_doc_to_urls(router_and_urls, (url, Arc::new(ApiDoc::Utoipa(openapi))))
3232
},
3333
);
3434
let (router, urls) = swagger_ui.external_urls.into_iter().fold(
3535
(router, urls),
3636
|router_and_urls, (url, openapi)| {
37-
add_api_doc_to_urls(router_and_urls, (url, ApiDoc::Value(openapi)))
37+
add_api_doc_to_urls(router_and_urls, (url, Arc::new(ApiDoc::Value(openapi))))
3838
},
3939
);
4040

@@ -108,7 +108,7 @@ where
108108

109109
fn add_api_doc_to_urls<S>(
110110
router_and_urls: (Router<S>, Vec<Url<'static>>),
111-
url: (Url<'static>, ApiDoc),
111+
url: (Url<'static>, Arc<ApiDoc>),
112112
) -> (Router<S>, Vec<Url<'static>>)
113113
where
114114
S: Clone + Send + Sync + 'static,

0 commit comments

Comments
 (0)