diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index b8651a39d..d9d840992 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -15,11 +15,17 @@ use utoipa::ToSchema; pub struct ResponseError { #[serde(skip)] pub code: StatusCode, + /// The error message. pub message: String, + /// The error code. + #[schema(value_type = Code)] #[serde(rename = "code")] error_code: String, + /// The error type. + #[schema(value_type = ErrorType)] #[serde(rename = "type")] error_type: String, + /// A link to the documentation about this specific error. #[serde(rename = "link")] error_link: String, } @@ -99,7 +105,9 @@ pub trait ErrorCode { } #[allow(clippy::enum_variant_names)] -enum ErrorType { +#[derive(ToSchema)] +#[schema(rename_all = "snake_case")] +pub enum ErrorType { Internal, InvalidRequest, Auth, @@ -131,7 +139,8 @@ impl fmt::Display for ErrorType { /// `MyErrorCode::default().error_code()`. macro_rules! make_error_codes { ($($code_ident:ident, $err_type:ident, $status:ident);*) => { - #[derive(Debug, Clone, Copy, PartialEq, Eq)] + #[derive(Debug, Clone, Copy, PartialEq, Eq, ToSchema)] + #[schema(rename_all = "snake_case")] pub enum Code { $($code_ident),* } diff --git a/meilisearch/src/routes/mod.rs b/meilisearch/src/routes/mod.rs index 7aadafafd..e4f89fc38 100644 --- a/meilisearch/src/routes/mod.rs +++ b/meilisearch/src/routes/mod.rs @@ -15,6 +15,7 @@ use serde::{Deserialize, Serialize}; use time::OffsetDateTime; use tracing::debug; use utoipa::OpenApi; +use utoipa::ToSchema; use utoipa_rapidoc::RapiDoc; use utoipa_scalar::{Scalar, Servable as ScalarServable}; @@ -108,14 +109,19 @@ pub fn is_dry_run(req: &HttpRequest, opt: &Opt) -> Result { .map_or(false, |s| s.to_lowercase() == "true")) } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, ToSchema)] #[serde(rename_all = "camelCase")] pub struct SummarizedTaskView { + /// The task unique identifier. task_uid: TaskId, + /// The index affected by this task. May be `null` if the task is not linked to any index. index_uid: Option, + /// The status of the task. status: Status, + /// The type of the task. #[serde(rename = "type")] kind: Kind, + /// The date on which the task was enqueued. #[serde(serialize_with = "time::serde::rfc3339::serialize")] enqueued_at: OffsetDateTime, } diff --git a/meilisearch/src/routes/tasks.rs b/meilisearch/src/routes/tasks.rs index 134798810..3134bb852 100644 --- a/meilisearch/src/routes/tasks.rs +++ b/meilisearch/src/routes/tasks.rs @@ -5,7 +5,7 @@ use deserr::Deserr; use index_scheduler::{IndexScheduler, Query, TaskId}; use meilisearch_types::deserr::query_params::Param; use meilisearch_types::deserr::DeserrQueryParamError; -use meilisearch_types::error::deserr_codes::*; +use meilisearch_types::error::{deserr_codes::*, Code, ErrorType}; use meilisearch_types::error::{InvalidTaskDateError, ResponseError}; use meilisearch_types::index_uid::IndexUid; use meilisearch_types::settings::{ @@ -43,7 +43,7 @@ const DEFAULT_LIMIT: u32 = 20; )), modifiers(&OpenApiAuth), - components(schemas(AllTasks, TaskView, Status, DetailsView, ResponseError, Settings, Settings, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings)) + components(schemas(Code, ErrorType, AllTasks, TaskView, Status, DetailsView, ResponseError, Settings, Settings, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings, SummarizedTaskView, Kind)) )] pub struct TaskApi; @@ -404,6 +404,7 @@ async fn delete_tasks( #[derive(Debug, Serialize, ToSchema)] pub struct AllTasks { + /// The list of tasks that matched the filter. results: Vec, /// Total number of browsable results using offset/limit parameters for the given resource. total: u64,