From cb7c1a8c47a871dde2b52ae28afad51c59d351ef Mon Sep 17 00:00:00 2001 From: Romain Lebran Date: Sat, 22 Jun 2024 18:32:28 +0200 Subject: [PATCH] Fix Resource wrap function --- apistos/src/internal/definition_holder.rs | 2 +- apistos/tests/routing.rs | 86 +++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 apistos/tests/routing.rs diff --git a/apistos/src/internal/definition_holder.rs b/apistos/src/internal/definition_holder.rs index 0f7eb3d8..ff443e7a 100644 --- a/apistos/src/internal/definition_holder.rs +++ b/apistos/src/internal/definition_holder.rs @@ -34,7 +34,7 @@ impl DefinitionHolder for RouteWrapper { } } -impl DefinitionHolder for Resource { +impl DefinitionHolder for Resource { fn path(&self) -> &str { &self.path } diff --git a/apistos/tests/routing.rs b/apistos/tests/routing.rs new file mode 100644 index 00000000..f3cb1bd5 --- /dev/null +++ b/apistos/tests/routing.rs @@ -0,0 +1,86 @@ +use actix_web::middleware::Logger; +use actix_web::web::{Json, Path}; +use actix_web::{App, Error}; + +use apistos::app::OpenApiWrapper; +use apistos::spec::Spec; +use apistos::web::{delete, get, patch, post, put, resource, scope, tagged_resource, tagged_scope, ServiceConfig}; +use apistos_gen::api_operation; +use apistos_models::info::Info; +use apistos_models::tag::Tag; + +#[test] +fn actix_routing() { + fn my_routes(cfg: &mut ServiceConfig) { + cfg.service( + resource("/users/{user_id}") + .route(delete().to(test)) + .wrap(Logger::default()), + ); + } + + #[api_operation(tag = "pet")] + pub(crate) async fn test(_params: Path<(u32, String)>) -> Result, Error> { + Ok(Json(())) + } + + let info = Info { + title: "A well documented API".to_string(), + description: Some("Really well document I mean it".to_string()), + terms_of_service: Some("https://terms.com".to_string()), + ..Default::default() + }; + let tags = vec![ + Tag { + name: "pet".to_owned(), + ..Default::default() + }, + Tag { + name: "A super tag".to_owned(), + ..Default::default() + }, + Tag { + name: "Another super tag".to_owned(), + ..Default::default() + }, + ]; + let spec = Spec { + info: info.clone(), + tags: tags.clone(), + ..Default::default() + }; + + App::new() + .document(spec) + .service( + scope("test") + .service(resource("/{plop_id}/{clap_name}").route(get().to(test))) + .service(tagged_resource("/line/{plop_id}", vec!["A super tag".to_string()]).route(put().to(test))) + .service( + tagged_scope("test2", vec!["Another super tag".to_string()]).service(resource("/").route(post().to(test))), + ) + .route("test3", patch().to(test)) + .app_data("") + .configure(my_routes), + ) + .build("/openapi.json"); +} + +// Imports bellow aim at making clippy happy. Those dependencies are necessary for integration-test. +use actix_service as _; +use actix_web_lab as _; +use apistos_core as _; +use apistos_plugins as _; +use apistos_rapidoc as _; +use apistos_redoc as _; +use apistos_scalar as _; +use apistos_swagger_ui as _; +use garde_actix_web as _; +use indexmap as _; +use log as _; +use md5 as _; +use once_cell as _; +use regex as _; +use schemars as _; +use serde as _; +use serde_json as _;