review all the return type

This commit is contained in:
Tamo 2024-12-30 11:40:58 +01:00
parent 5f55e88484
commit ac944f0960
No known key found for this signature in database
GPG Key ID: 20CD8020AFA88D69
5 changed files with 22 additions and 20 deletions

View File

@ -16,7 +16,7 @@ pub struct TaskView {
#[schema(value_type = u32, example = 4312)] #[schema(value_type = u32, example = 4312)]
pub uid: TaskId, pub uid: TaskId,
/// The unique identifier of the index where this task is operated. /// The unique identifier of the index where this task is operated.
#[schema(example = json!("movies"))] #[schema(value_type = Option<u32>, example = json!("movies"))]
pub batch_uid: Option<BatchId>, pub batch_uid: Option<BatchId>,
#[serde(default)] #[serde(default)]
pub index_uid: Option<String>, pub index_uid: Option<String>,

View File

@ -16,7 +16,7 @@ use time::OffsetDateTime;
use utoipa::{IntoParams, OpenApi, ToSchema}; use utoipa::{IntoParams, OpenApi, ToSchema};
use uuid::Uuid; 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::policies::*;
use crate::extractors::authentication::GuardedData; use crate::extractors::authentication::GuardedData;
use crate::extractors::sequential_extractor::SeqHandler; use crate::extractors::sequential_extractor::SeqHandler;
@ -134,7 +134,6 @@ impl ListApiKeys {
/// Get API Keys /// Get API Keys
/// ///
/// List all API Keys /// List all API Keys
/// TODO: Tamo fix the return type
#[utoipa::path( #[utoipa::path(
get, get,
path = "/", path = "/",
@ -142,7 +141,7 @@ impl ListApiKeys {
security(("Bearer" = ["keys.get", "keys.*", "*"])), security(("Bearer" = ["keys.get", "keys.*", "*"])),
params(ListApiKeys), params(ListApiKeys),
responses( 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<KeyView>, content_type = "application/json", example = json!(
{ {
"results": [ "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. /// Update the name and description of an API key.
/// Only the `name` and `description` of the api key can be updated. /// 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.
/// If there is an issue with the `key` or `uid` of a key, then you must recreate one from scratch.
#[utoipa::path( #[utoipa::path(
patch, patch,
path = "/{uidOrKey}", 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. /// Delete the specified API key.
/// 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.
#[utoipa::path( #[utoipa::path(
delete, delete,
path = "/{uidOrKey}", path = "/{uidOrKey}",

View File

@ -372,25 +372,30 @@ pub async fn delete_document(
Ok(HttpResponse::Accepted().json(task)) Ok(HttpResponse::Accepted().json(task))
} }
#[derive(Debug, Deserr)] #[derive(Debug, Deserr, IntoParams)]
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)] #[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
#[into_params(rename_all = "camelCase", parameter_in = Query)]
pub struct BrowseQueryGet { pub struct BrowseQueryGet {
#[param(default, value_type = Option<usize>)]
#[deserr(default, error = DeserrQueryParamError<InvalidDocumentOffset>)] #[deserr(default, error = DeserrQueryParamError<InvalidDocumentOffset>)]
offset: Param<usize>, offset: Param<usize>,
#[param(default, value_type = Option<usize>)]
#[deserr(default = Param(PAGINATION_DEFAULT_LIMIT), error = DeserrQueryParamError<InvalidDocumentLimit>)] #[deserr(default = Param(PAGINATION_DEFAULT_LIMIT), error = DeserrQueryParamError<InvalidDocumentLimit>)]
limit: Param<usize>, limit: Param<usize>,
#[param(default, value_type = Option<Vec<String>>)]
#[deserr(default, error = DeserrQueryParamError<InvalidDocumentFields>)] #[deserr(default, error = DeserrQueryParamError<InvalidDocumentFields>)]
fields: OptionStarOrList<String>, fields: OptionStarOrList<String>,
#[param(default, value_type = Option<bool>)]
#[deserr(default, error = DeserrQueryParamError<InvalidDocumentRetrieveVectors>)] #[deserr(default, error = DeserrQueryParamError<InvalidDocumentRetrieveVectors>)]
retrieve_vectors: Param<bool>, retrieve_vectors: Param<bool>,
#[param(default, value_type = Option<String>, example = "popularity > 1000")]
#[deserr(default, error = DeserrQueryParamError<InvalidDocumentFilter>)] #[deserr(default, error = DeserrQueryParamError<InvalidDocumentFilter>)]
filter: Option<String>, filter: Option<String>,
} }
#[derive(Debug, Deserr, IntoParams, ToSchema)] #[derive(Debug, Deserr, ToSchema)]
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
#[schema(rename_all = "camelCase")] #[schema(rename_all = "camelCase")]
#[into_params(rename_all = "camelCase", parameter_in = Query)]
pub struct BrowseQuery { pub struct BrowseQuery {
#[schema(default, example = 150)] #[schema(default, example = 150)]
#[deserr(default, error = DeserrJsonError<InvalidDocumentOffset>)] #[deserr(default, error = DeserrJsonError<InvalidDocumentOffset>)]
@ -404,7 +409,7 @@ pub struct BrowseQuery {
#[schema(default, example = true)] #[schema(default, example = true)]
#[deserr(default, error = DeserrJsonError<InvalidDocumentRetrieveVectors>)] #[deserr(default, error = DeserrJsonError<InvalidDocumentRetrieveVectors>)]
retrieve_vectors: bool, retrieve_vectors: bool,
#[schema(default, example = "popularity > 1000")] #[schema(default, value_type = Option<Value>, example = "popularity > 1000")]
#[deserr(default, error = DeserrJsonError<InvalidDocumentFilter>)] #[deserr(default, error = DeserrJsonError<InvalidDocumentFilter>)]
filter: Option<Value>, filter: Option<Value>,
} }
@ -494,7 +499,7 @@ pub async fn documents_by_query_post(
security(("Bearer" = ["documents.get", "documents.*", "*"])), security(("Bearer" = ["documents.get", "documents.*", "*"])),
params( params(
("indexUid", example = "movies", description = "Index Unique Identifier", nullable = false), ("indexUid", example = "movies", description = "Index Unique Identifier", nullable = false),
BrowseQuery BrowseQueryGet
), ),
responses( responses(
(status = 200, description = "The documents are returned", body = PaginationView<serde_json::Value>, content_type = "application/json", example = json!( (status = 200, description = "The documents are returned", body = PaginationView<serde_json::Value>, content_type = "application/json", example = json!(

View File

@ -234,9 +234,8 @@ macro_rules! make_setting_route {
tag = "Settings", tag = "Settings",
security(("Bearer" = ["settings.get", "settings.*", "*"])), security(("Bearer" = ["settings.get", "settings.*", "*"])),
params(("indexUid", example = "movies", description = "Index Unique Identifier", nullable = false)), params(("indexUid", example = "movies", description = "Index Unique Identifier", nullable = false)),
request_body = $type,
responses( 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() <$type>::default()
)), )),
(status = 401, description = "The authorization header is missing", body = ResponseError, content_type = "application/json", example = json!( (status = 401, description = "The authorization header is missing", body = ResponseError, content_type = "application/json", example = json!(

View File

@ -8,6 +8,7 @@ use crate::routes::batches::AllBatches;
use crate::routes::features::RuntimeTogglableFeatures; use crate::routes::features::RuntimeTogglableFeatures;
use crate::routes::indexes::documents::DocumentDeletionByFilter; use crate::routes::indexes::documents::DocumentDeletionByFilter;
use crate::routes::indexes::documents::DocumentEditionByFunction; use crate::routes::indexes::documents::DocumentEditionByFunction;
use crate::routes::indexes::IndexView;
use crate::routes::multi_search::SearchResults; use crate::routes::multi_search::SearchResults;
use crate::routes::swap_indexes::SwapIndexesPayload; use crate::routes::swap_indexes::SwapIndexesPayload;
use crate::search::{ 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."), (name = "Stats", description = "Stats gives extended information and metrics about indexes and the Meilisearch database."),
), ),
modifiers(&OpenApiAuth), modifiers(&OpenApiAuth),
components(schemas(DocumentDeletionByFilter, AllBatches, BatchStats, ProgressStepView, ProgressView, BatchView, RuntimeTogglableFeatures, SwapIndexesPayload, DocumentEditionByFunction, MergeFacets, FederationOptions, SearchQueryWithIndex, Federation, FederatedSearch, FederatedSearchResult, SearchResults, SearchResultWithIndex, SimilarQuery, SimilarResult, PaginationView<serde_json::Value>, BrowseQuery, UpdateIndexRequest, IndexUid, IndexCreateRequest, KeyView, Action, CreateApiKey, UpdateStderrLogs, LogMode, GetLogs, IndexStats, Stats, HealthStatus, HealthResponse, VersionResponse, Code, ErrorType, AllTasks, TaskView, Status, DetailsView, ResponseError, Settings<Unchecked>, Settings<Checked>, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings, SummarizedTaskView, Kind)) components(schemas(PaginationView<KeyView>, PaginationView<IndexView>, IndexView, DocumentDeletionByFilter, AllBatches, BatchStats, ProgressStepView, ProgressView, BatchView, RuntimeTogglableFeatures, SwapIndexesPayload, DocumentEditionByFunction, MergeFacets, FederationOptions, SearchQueryWithIndex, Federation, FederatedSearch, FederatedSearchResult, SearchResults, SearchResultWithIndex, SimilarQuery, SimilarResult, PaginationView<serde_json::Value>, BrowseQuery, UpdateIndexRequest, IndexUid, IndexCreateRequest, KeyView, Action, CreateApiKey, UpdateStderrLogs, LogMode, GetLogs, IndexStats, Stats, HealthStatus, HealthResponse, VersionResponse, Code, ErrorType, AllTasks, TaskView, Status, DetailsView, ResponseError, Settings<Unchecked>, Settings<Checked>, TypoSettings, MinWordSizeTyposSetting, FacetingSettings, PaginationSettings, SummarizedTaskView, Kind))
)] )]
pub struct MeilisearchApi; pub struct MeilisearchApi;
@ -200,6 +201,7 @@ pub struct Pagination {
#[derive(Debug, Clone, Serialize, ToSchema)] #[derive(Debug, Clone, Serialize, ToSchema)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
#[schema(rename_all = "camelCase")]
pub struct PaginationView<T> { pub struct PaginationView<T> {
pub results: Vec<T>, pub results: Vec<T>,
pub offset: usize, pub offset: usize,