Skip to content

Commit 9e85e0e

Browse files
authored
Add map for ServiceConfig (#1174)
This commit adds `map` function for `ServiceConfig` to allow defining normal services to `actix_web::web::ServiceConfig` via `ServiceConfig` in similar fashion to `Scope` and `UtoipaApp`. This example demonstrates the `map` functionality of `ServiceConfig` to allow direct access to underlying `actix_web::web::ServiceConfig`. ```rust fn config(cfg: &mut service_config::ServiceConfig) { cfg.service(handler3) .map(|config| config.service(normal_service)); } ``` Closes #1173
1 parent 9a09e7a commit 9e85e0e

4 files changed

Lines changed: 31 additions & 5 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.1 - Oct 30 2024
4+
5+
### Changed
6+
7+
* Add `map` support for `ServiceConfig` (https://github.com/juhaku/utoipa/pull/1174)
8+
39
## 0.1.0 - Oct 23 2024
410

511
### Added

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.0"
4+
version = "0.1.1"
55
edition = "2021"
66
license = "MIT OR Apache-2.0"
77
readme = "README.md"

utoipa-actix-web/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,10 @@ mod tests {
363363
#![allow(unused)]
364364

365365
use actix_service::Service;
366-
use actix_web::guard::Guard;
366+
use actix_web::guard::{Get, Guard};
367367
use actix_web::http::header::{HeaderValue, CONTENT_TYPE};
368-
use actix_web::web::Data;
369-
use actix_web::{get, App};
368+
use actix_web::web::{self, Data};
369+
use actix_web::{get, App, HttpRequest, HttpResponse};
370370
use utoipa::ToSchema;
371371

372372
use super::*;
@@ -441,10 +441,16 @@ mod tests {
441441
}
442442
}
443443

444+
#[get("/normal_service")]
445+
async fn normal_service() -> &'static str {
446+
"str"
447+
}
448+
444449
#[test]
445450
fn test_app_generate_correct_openapi() {
446451
fn config(cfg: &mut service_config::ServiceConfig) {
447-
cfg.service(handler3);
452+
cfg.service(handler3)
453+
.map(|config| config.service(normal_service));
448454
}
449455

450456
let (_, mut api) = App::new()

utoipa-actix-web/src/service_config.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,18 @@ impl<'s> ServiceConfig<'s> {
9494
self.0.external_resource(name, url);
9595
self
9696
}
97+
98+
/// Synonymous for [`UtoipaApp::map`][utoipa_app_map]
99+
///
100+
/// [utoipa_app_map]: ../struct.UtoipaApp.html#method.map
101+
pub fn map<
102+
F: FnOnce(&mut actix_web::web::ServiceConfig) -> &mut actix_web::web::ServiceConfig,
103+
>(
104+
&mut self,
105+
op: F,
106+
) -> &mut Self {
107+
op(self.0);
108+
109+
self
110+
}
97111
}

0 commit comments

Comments
 (0)