Skip to content

Commit

Permalink
Add test for date types in actix params
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Sep 10, 2023
1 parent b1ce2d0 commit cde0eda
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ elif [[ "$crate" == "utoipa-gen" ]]; then

cargo test -p utoipa-gen --test schema_derive_test --features decimal_float
cargo test -p utoipa-gen --test path_derive_auto_into_responses --features auto_into_responses,utoipa/uuid,uuid
cargo test -p utoipa-gen --test path_derive_actix --test path_parameter_derive_actix --features actix_extras,utoipa/uuid,uuid
cargo test -p utoipa-gen --test path_derive_actix --test path_parameter_derive_actix --features actix_extras,utoipa/uuid,uuid,chrono,time
cargo test -p utoipa-gen --test path_derive_auto_into_responses_actix --features actix_extras,utoipa/auto_into_responses,utoipa/uuid,uuid

cargo test -p utoipa-gen --test path_derive_rocket --features rocket_extras
Expand Down
55 changes: 55 additions & 0 deletions utoipa-gen/tests/path_derive_actix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,61 @@ fn derive_path_with_multiple_args_with_descriptions() {
};
}

#[test]
fn derive_path_with_date_params() {
mod mod_derive_path_with_date_params {
use actix_web::{get, web, HttpResponse, Responder};
use chrono::{DateTime, Utc};
use serde_json::json;
use time::Date;

#[utoipa::path(
responses(
(status = 200, description = "success response")
),
params(
("start_date", description = "Start date filter"),
("end_date", description = "End date filter"),
)
)]
#[get("/visitors/v1/{start_date}/{end_date}")]
#[allow(unused)]
async fn get_foo_by_date(path: web::Path<(Date, DateTime<Utc>)>) -> impl Responder {
let (start_date, end_date) = path.into_inner();
HttpResponse::Ok()
.json(json!({ "params": &format!("{:?} {:?}", start_date, end_date) }))
}
}

#[derive(OpenApi, Default)]
#[openapi(paths(mod_derive_path_with_date_params::get_foo_by_date))]
struct ApiDoc;

let doc = serde_json::to_value(ApiDoc::openapi()).unwrap();
let parameters = doc
.pointer("/paths/~1visitors~1v1~1{start_date}~1{end_date}/get/parameters")
.unwrap();

common::assert_json_array_len(parameters, 2);
assert_value! {parameters=>
"[0].in" = r#""path""#, "Parameter in"
"[0].name" = r#""start_date""#, "Parameter name"
"[0].description" = r#""Start date filter""#, "Parameter description"
"[0].required" = r#"true"#, "Parameter required"
"[0].deprecated" = r#"null"#, "Parameter deprecated"
"[0].schema.type" = r#""string""#, "Parameter schema type"
"[0].schema.format" = r#""date""#, "Parameter schema format"

"[1].in" = r#""path""#, "Parameter in"
"[1].name" = r#""end_date""#, "Parameter name"
"[1].description" = r#""End date filter""#, "Parameter description"
"[1].required" = r#"true"#, "Parameter required"
"[1].deprecated" = r#"null"#, "Parameter deprecated"
"[1].schema.type" = r#""string""#, "Parameter schema type"
"[1].schema.format" = r#""date-time""#, "Parameter schema format"
};
}

#[test]
fn derive_path_with_context_path() {
use actix_web::{get, HttpResponse, Responder};
Expand Down

0 comments on commit cde0eda

Please sign in to comment.