Skip to content

Commit

Permalink
Fix wrong generated path with route function (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
rlebran authored Aug 4, 2024
2 parents c8da7e2 + ae7fbd3 commit 4e37325
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apistos/src/internal/actix/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 26 additions & 3 deletions apistos/tests/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -50,7 +50,7 @@ fn actix_routing() {
..Default::default()
};

App::new()
let app = App::new()
.document(spec)
.service(
scope("test")
Expand All @@ -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 _;
Expand Down

0 comments on commit 4e37325

Please sign in to comment.