Skip to content

Commit 478b7c9

Browse files
authored
Added a passthrough for scoped middleware in actix-web (#1196)
Add passthrough for `wrap` function in Scope.
1 parent 44ded6b commit 478b7c9

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

utoipa-actix-web/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog - utoipa-actix-web
22

3+
## 0.1.2 - Nov 8 2024
4+
5+
### Added
6+
7+
* Add passthrough for `Scope::wrap` (https://github.com/juhaku/utoipa/pull/1196)
8+
39
## 0.1.1 - Oct 30 2024
410

511
### Changed

utoipa-actix-web/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "utoipa-actix-web"
33
description = "Utoipa's actix-web bindings for seamless integration of the two"
4-
version = "0.1.1"
4+
version = "0.1.2"
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
77
readme = "README.md"

utoipa-actix-web/src/scope.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use core::fmt;
66
use std::cell::{Cell, RefCell};
77

8-
use actix_service::{IntoServiceFactory, ServiceFactory};
8+
use actix_service::{IntoServiceFactory, ServiceFactory, Transform};
99
use actix_web::body::MessageBody;
1010
use actix_web::dev::{AppService, HttpServiceFactory, ServiceRequest, ServiceResponse};
1111
use actix_web::guard::Guard;
@@ -97,6 +97,33 @@ where
9797
Self(self.0.app_data(data), self.1, self.2)
9898
}
9999

100+
/// Passthrough implementation for [`actix_web::Scope::wrap`].
101+
pub fn wrap<M, B>(
102+
self,
103+
middleware: M,
104+
) -> Scope<
105+
impl ServiceFactory<
106+
ServiceRequest,
107+
Config = (),
108+
Response = ServiceResponse<B>,
109+
Error = Error,
110+
InitError = (),
111+
>,
112+
>
113+
where
114+
M: Transform<
115+
T::Service,
116+
ServiceRequest,
117+
Response = ServiceResponse<B>,
118+
Error = Error,
119+
InitError = (),
120+
> + 'static,
121+
B: MessageBody,
122+
{
123+
let scope = self.0.wrap(middleware);
124+
Scope(scope, self.1, self.2)
125+
}
126+
100127
/// Synonymous for [`UtoipaApp::configure`][utoipa_app_configure]
101128
///
102129
/// [utoipa_app_configure]: ../struct.UtoipaApp.html#method.configure

0 commit comments

Comments
 (0)