Skip to content

Commit

Permalink
Added a passthrough for scoped middleware in actix-web (#1196)
Browse files Browse the repository at this point in the history
Add passthrough for `wrap` function in Scope.
  • Loading branch information
nico-incubiq authored Nov 8, 2024
1 parent 44ded6b commit 478b7c9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 6 additions & 0 deletions utoipa-actix-web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog - utoipa-actix-web

## 0.1.2 - Nov 8 2024

### Added

* Add passthrough for `Scope::wrap` (https://github.com/juhaku/utoipa/pull/1196)

## 0.1.1 - Oct 30 2024

### Changed
Expand Down
2 changes: 1 addition & 1 deletion utoipa-actix-web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "utoipa-actix-web"
description = "Utoipa's actix-web bindings for seamless integration of the two"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
29 changes: 28 additions & 1 deletion utoipa-actix-web/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use core::fmt;
use std::cell::{Cell, RefCell};

use actix_service::{IntoServiceFactory, ServiceFactory};
use actix_service::{IntoServiceFactory, ServiceFactory, Transform};
use actix_web::body::MessageBody;
use actix_web::dev::{AppService, HttpServiceFactory, ServiceRequest, ServiceResponse};
use actix_web::guard::Guard;
Expand Down Expand Up @@ -97,6 +97,33 @@ where
Self(self.0.app_data(data), self.1, self.2)
}

/// Passthrough implementation for [`actix_web::Scope::wrap`].
pub fn wrap<M, B>(
self,
middleware: M,
) -> Scope<
impl ServiceFactory<
ServiceRequest,
Config = (),
Response = ServiceResponse<B>,
Error = Error,
InitError = (),
>,
>
where
M: Transform<
T::Service,
ServiceRequest,
Response = ServiceResponse<B>,
Error = Error,
InitError = (),
> + 'static,
B: MessageBody,
{
let scope = self.0.wrap(middleware);
Scope(scope, self.1, self.2)
}

/// Synonymous for [`UtoipaApp::configure`][utoipa_app_configure]
///
/// [utoipa_app_configure]: ../struct.UtoipaApp.html#method.configure
Expand Down

0 comments on commit 478b7c9

Please sign in to comment.