From ae7fbd38822e974e740c23ffd2cda5fcf9bfbd5f Mon Sep 17 00:00:00 2001 From: Romain Lebran Date: Sun, 4 Aug 2024 13:20:53 +0200 Subject: [PATCH] Fix wrong generated path with route function --- apistos/src/internal/actix/scope.rs | 2 +- apistos/tests/routing.rs | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/apistos/src/internal/actix/scope.rs b/apistos/src/internal/actix/scope.rs index 55c4fff2..abe0c30e 100644 --- a/apistos/src/internal/actix/scope.rs +++ b/apistos/src/internal/actix/scope.rs @@ -107,7 +107,7 @@ where /// Wrapper for [`actix_web::Scope::route`](https://docs.rs/actix-web/*/actix_web/struct.Scope.html#method.route). pub fn route(mut self, path: &str, route: Route) -> Self { - let mut w = RouteWrapper::new(&self.path, route); + let mut w = RouteWrapper::new(path, route); self.update_from_def_holder(&mut w); self.inner = self.inner.take().map(|s| s.route(path, w.inner)); self diff --git a/apistos/tests/routing.rs b/apistos/tests/routing.rs index f3cb1bd5..8e21332f 100644 --- a/apistos/tests/routing.rs +++ b/apistos/tests/routing.rs @@ -9,8 +9,8 @@ use apistos_gen::api_operation; use apistos_models::info::Info; use apistos_models::tag::Tag; -#[test] -fn actix_routing() { +#[actix_web::test] +async fn actix_routing() { fn my_routes(cfg: &mut ServiceConfig) { cfg.service( resource("/users/{user_id}") @@ -50,7 +50,7 @@ fn actix_routing() { ..Default::default() }; - App::new() + let app = App::new() .document(spec) .service( scope("test") @@ -60,16 +60,39 @@ fn actix_routing() { tagged_scope("test2", vec!["Another super tag".to_string()]).service(resource("/").route(post().to(test))), ) .route("test3", patch().to(test)) + .route("test4/{test_id}", patch().to(test)) .app_data("") .configure(my_routes), ) .build("/openapi.json"); + let app = init_service(app).await; + + let req = TestRequest::get().uri("/openapi.json").to_request(); + let resp = call_service(&app, req).await; + assert!(resp.status().is_success()); + + let body: OpenApi = try_read_body_json(resp).await.expect("Unable to read body"); + let mut paths: Vec<&String> = body.paths.paths.keys().collect(); + paths.sort(); + + let expected_paths = vec![ + "/test/line/{plop_id}", + "/test/test2/", + "/test/test3", + "/test/test4/{test_id}", + "/test/users/{user_id}", + "/test/{plop_id}/{clap_name}", + ]; + + assert_eq!(paths, expected_paths) } // Imports bellow aim at making clippy happy. Those dependencies are necessary for integration-test. use actix_service as _; +use actix_web::test::{call_service, init_service, try_read_body_json, TestRequest}; use actix_web_lab as _; use apistos_core as _; +use apistos_models::OpenApi; use apistos_plugins as _; use apistos_rapidoc as _; use apistos_redoc as _;