From ac944f0960e5a04378e83bbe2abd35223267ed64 Mon Sep 17 00:00:00 2001 From: Tamo Date: Mon, 30 Dec 2024 11:40:58 +0100 Subject: [PATCH] review all the return type --- crates/meilisearch-types/src/task_view.rs | 2 +- crates/meilisearch/src/routes/api_key.rs | 18 +++++++----------- .../src/routes/indexes/documents.rs | 15 ++++++++++----- .../meilisearch/src/routes/indexes/settings.rs | 3 +-- crates/meilisearch/src/routes/mod.rs | 4 +++- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/crates/meilisearch-types/src/task_view.rs b/crates/meilisearch-types/src/task_view.rs index 23af055d6..6032843aa 100644 --- a/crates/meilisearch-types/src/task_view.rs +++ b/crates/meilisearch-types/src/task_view.rs @@ -16,7 +16,7 @@ pub struct TaskView { #[schema(value_type = u32, example = 4312)] pub uid: TaskId, /// The unique identifier of the index where this task is operated. - #[schema(example = json!("movies"))] + #[schema(value_type = Option, example = json!("movies"))] pub batch_uid: Option, #[serde(default)] pub index_uid: Option, diff --git a/crates/meilisearch/src/routes/api_key.rs b/crates/meilisearch/src/routes/api_key.rs index a0c34c3e4..e45326069 100644 --- a/crates/meilisearch/src/routes/api_key.rs +++ b/crates/meilisearch/src/routes/api_key.rs @@ -16,7 +16,7 @@ use time::OffsetDateTime; use utoipa::{IntoParams, OpenApi, ToSchema}; use uuid::Uuid; -use super::{PAGINATION_DEFAULT_LIMIT, PAGINATION_DEFAULT_LIMIT_FN}; +use super::{PaginationView, PAGINATION_DEFAULT_LIMIT, PAGINATION_DEFAULT_LIMIT_FN}; use crate::extractors::authentication::policies::*; use crate::extractors::authentication::GuardedData; use crate::extractors::sequential_extractor::SeqHandler; @@ -134,7 +134,6 @@ impl ListApiKeys { /// Get API Keys /// /// List all API Keys -/// TODO: Tamo fix the return type #[utoipa::path( get, path = "/", @@ -142,7 +141,7 @@ impl ListApiKeys { security(("Bearer" = ["keys.get", "keys.*", "*"])), params(ListApiKeys), responses( - (status = 202, description = "List of keys", body = serde_json::Value, content_type = "application/json", example = json!( + (status = 202, description = "List of keys", body = PaginationView, content_type = "application/json", example = json!( { "results": [ { @@ -268,11 +267,10 @@ pub async fn get_api_key( } -/// Update an API Key +/// Update a Key /// -/// Update an API key from its `uid` or its `key` field. -/// Only the `name` and `description` of the api key can be updated. -/// If there is an issue with the `key` or `uid` of a key, then you must recreate one from scratch. +/// Update the name and description of an API key. +/// Updates to keys are partial. This means you should provide only the fields you intend to update, as any fields not present in the payload will remain unchanged. #[utoipa::path( patch, path = "/{uidOrKey}", @@ -338,11 +336,9 @@ pub async fn patch_api_key( -/// Update an API Key +/// Delete a key /// -/// Update an API key from its `uid` or its `key` field. -/// Only the `name` and `description` of the api key can be updated. -/// If there is an issue with the `key` or `uid` of a key, then you must recreate one from scratch. +/// Delete the specified API key. #[utoipa::path( delete, path = "/{uidOrKey}", diff --git a/crates/meilisearch/src/routes/indexes/documents.rs b/crates/meilisearch/src/routes/indexes/documents.rs index d93f5df9f..3da24859d 100644 --- a/crates/meilisearch/src/routes/indexes/documents.rs +++ b/crates/meilisearch/src/routes/indexes/documents.rs @@ -372,25 +372,30 @@ pub async fn delete_document( Ok(HttpResponse::Accepted().json(task)) } -#[derive(Debug, Deserr)] +#[derive(Debug, Deserr, IntoParams)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] +#[into_params(rename_all = "camelCase", parameter_in = Query)] pub struct BrowseQueryGet { + #[param(default, value_type = Option)] #[deserr(default, error = DeserrQueryParamError)] offset: Param, + #[param(default, value_type = Option)] #[deserr(default = Param(PAGINATION_DEFAULT_LIMIT), error = DeserrQueryParamError)] limit: Param, + #[param(default, value_type = Option>)] #[deserr(default, error = DeserrQueryParamError)] fields: OptionStarOrList, + #[param(default, value_type = Option)] #[deserr(default, error = DeserrQueryParamError)] retrieve_vectors: Param, + #[param(default, value_type = Option, example = "popularity > 1000")] #[deserr(default, error = DeserrQueryParamError)] filter: Option, } -#[derive(Debug, Deserr, IntoParams, ToSchema)] +#[derive(Debug, Deserr, ToSchema)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] #[schema(rename_all = "camelCase")] -#[into_params(rename_all = "camelCase", parameter_in = Query)] pub struct BrowseQuery { #[schema(default, example = 150)] #[deserr(default, error = DeserrJsonError)] @@ -404,7 +409,7 @@ pub struct BrowseQuery { #[schema(default, example = true)] #[deserr(default, error = DeserrJsonError)] retrieve_vectors: bool, - #[schema(default, example = "popularity > 1000")] + #[schema(default, value_type = Option, example = "popularity > 1000")] #[deserr(default, error = DeserrJsonError)] filter: Option, } @@ -494,7 +499,7 @@ pub async fn documents_by_query_post( security(("Bearer" = ["documents.get", "documents.*", "*"])), params( ("indexUid", example = "movies", description = "Index Unique Identifier", nullable = false), - BrowseQuery + BrowseQueryGet ), responses( (status = 200, description = "The documents are returned", body = PaginationView, content_type = "application/json", example = json!( diff --git a/crates/meilisearch/src/routes/indexes/settings.rs b/crates/meilisearch/src/routes/indexes/settings.rs index 17319f830..58197acda 100644 --- a/crates/meilisearch/src/routes/indexes/settings.rs +++ b/crates/meilisearch/src/routes/indexes/settings.rs @@ -234,9 +234,8 @@ macro_rules! make_setting_route { tag = "Settings", security(("Bearer" = ["settings.get", "settings.*", "*"])), params(("indexUid", example = "movies", description = "Index Unique Identifier", nullable = false)), - request_body = $type, responses( - (status = 200, description = concat!($camelcase_attr, " is returned"), body = SummarizedTaskView, content_type = "application/json", example = json!( + (status = 200, description = concat!($camelcase_attr, " is returned"), body = $type, content_type = "application/json", example = json!( <$type>::default() )), (status = 401, description = "The authorization header is missing", body = ResponseError, content_type = "application/json", example = json!( diff --git a/crates/meilisearch/src/routes/mod.rs b/crates/meilisearch/src/routes/mod.rs index bf51ed4de..684234be4 100644 --- a/crates/meilisearch/src/routes/mod.rs +++ b/crates/meilisearch/src/routes/mod.rs @@ -8,6 +8,7 @@ use crate::routes::batches::AllBatches; use crate::routes::features::RuntimeTogglableFeatures; use crate::routes::indexes::documents::DocumentDeletionByFilter; use crate::routes::indexes::documents::DocumentEditionByFunction; +use crate::routes::indexes::IndexView; use crate::routes::multi_search::SearchResults; use crate::routes::swap_indexes::SwapIndexesPayload; use crate::search::{ @@ -87,7 +88,7 @@ pub mod tasks; (name = "Stats", description = "Stats gives extended information and metrics about indexes and the Meilisearch database."), ), modifiers(&OpenApiAuth), - components(schemas(DocumentDeletionByFilter, AllBatches, BatchStats, ProgressStepView, ProgressView, BatchView, RuntimeTogglableFeatures, SwapIndexesPayload, DocumentEditionByFunction, MergeFacets, FederationOptions, SearchQueryWithIndex, Federation, FederatedSearch, FederatedSearchResult, SearchResults, SearchResultWithIndex, SimilarQuery, SimilarResult, PaginationView, BrowseQuery, UpdateIndexRequest, IndexUid, IndexCreateRequest, KeyView, Action, CreateApiKey, UpdateStderrLogs, LogMode, GetLogs, IndexStats, Stats, HealthStatus, HealthResponse, VersionResponse, Code, ErrorType, AllTasks, TaskView, Status, DetailsView, ResponseError, Settings, Settings, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings, SummarizedTaskView, Kind)) + components(schemas(PaginationView, PaginationView, IndexView, DocumentDeletionByFilter, AllBatches, BatchStats, ProgressStepView, ProgressView, BatchView, RuntimeTogglableFeatures, SwapIndexesPayload, DocumentEditionByFunction, MergeFacets, FederationOptions, SearchQueryWithIndex, Federation, FederatedSearch, FederatedSearchResult, SearchResults, SearchResultWithIndex, SimilarQuery, SimilarResult, PaginationView, BrowseQuery, UpdateIndexRequest, IndexUid, IndexCreateRequest, KeyView, Action, CreateApiKey, UpdateStderrLogs, LogMode, GetLogs, IndexStats, Stats, HealthStatus, HealthResponse, VersionResponse, Code, ErrorType, AllTasks, TaskView, Status, DetailsView, ResponseError, Settings, Settings, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings, SummarizedTaskView, Kind)) )] pub struct MeilisearchApi; @@ -200,6 +201,7 @@ pub struct Pagination { #[derive(Debug, Clone, Serialize, ToSchema)] #[serde(rename_all = "camelCase")] +#[schema(rename_all = "camelCase")] pub struct PaginationView { pub results: Vec, pub offset: usize,