From 4a1d4460bdd81b27aa6d36b03d02b7a3f6b7e736 Mon Sep 17 00:00:00 2001 From: Tamo Date: Wed, 9 Oct 2024 16:23:05 +0200 Subject: [PATCH] bump utoipa to the latest rc and make the list key route compile --- Cargo.lock | 17 +++++++++-------- meilisearch-types/Cargo.toml | 2 +- meilisearch-types/src/deserr/query_params.rs | 12 +++++++++--- meilisearch-types/src/facet_values_sort.rs | 3 ++- meilisearch-types/src/locales.rs | 5 +++-- meilisearch-types/src/settings.rs | 8 +++++--- meilisearch/Cargo.toml | 6 +++--- meilisearch/src/routes/api_key.rs | 5 +++-- meilisearch/src/routes/indexes/mod.rs | 1 + meilisearch/src/routes/mod.rs | 8 ++++---- milli/Cargo.toml | 1 + milli/src/localized_attributes_rules.rs | 4 +++- milli/src/update/settings.rs | 13 +++++++++++++ 13 files changed, 57 insertions(+), 28 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b5766a416..95bd2c0f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3608,6 +3608,7 @@ dependencies = [ "tracing", "ureq", "url", + "utoipa", "uuid", ] @@ -5847,9 +5848,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] name = "utoipa" -version = "5.0.0-beta.0" +version = "5.0.0-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86fac56d240b49c629b9083c932ac20a23d926937e67c21ba209f836e2983d4f" +checksum = "3cf66139459b75afa33caddb62bb2afee3838923b630b9e0ef38c369e543382f" dependencies = [ "indexmap", "serde", @@ -5859,9 +5860,9 @@ dependencies = [ [[package]] name = "utoipa-gen" -version = "5.0.0-beta.0" +version = "5.0.0-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31d88270777931b8133b119c953062bd41665bb8507841f7d433f46d2765e9d4" +checksum = "7c136da726bb82a527afa1fdf3f4619eaf104e2982f071f25239cef1c67c79eb" dependencies = [ "proc-macro2", "quote", @@ -5872,9 +5873,9 @@ dependencies = [ [[package]] name = "utoipa-rapidoc" -version = "4.0.1-beta.0" +version = "4.0.1-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c836d406d590721b89f572cb0379479fcfbe27f31ca65c0775265a1b9026dd34" +checksum = "a4d3324d5874fb734762214827dd30b47aa78510d12abab674a97f6d7c53688f" dependencies = [ "actix-web", "serde", @@ -5884,9 +5885,9 @@ dependencies = [ [[package]] name = "utoipa-scalar" -version = "0.2.0-beta.0" +version = "0.2.0-rc.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc86065a210b8540e46d15e0844765d1d14eec7fd6221c2b0de8f6edde990648" +checksum = "7dc122c11f9642b20b3be88b60c1a3672319811f139698ac6999e72992ac7c7e" dependencies = [ "actix-web", "serde", diff --git a/meilisearch-types/Cargo.toml b/meilisearch-types/Cargo.toml index 10b8b1bfb..52037f685 100644 --- a/meilisearch-types/Cargo.toml +++ b/meilisearch-types/Cargo.toml @@ -37,7 +37,7 @@ time = { version = "0.3.36", features = [ "macros", ] } tokio = "1.38" -utoipa = { version = "5.0.0-beta.0" } +utoipa = { version = "5.0.0-rc.0", features = ["macros"] } uuid = { version = "1.10.0", features = ["serde", "v4"] } [dev-dependencies] diff --git a/meilisearch-types/src/deserr/query_params.rs b/meilisearch-types/src/deserr/query_params.rs index d3ee25efa..58113567e 100644 --- a/meilisearch-types/src/deserr/query_params.rs +++ b/meilisearch-types/src/deserr/query_params.rs @@ -16,7 +16,7 @@ use std::ops::Deref; use std::str::FromStr; use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind}; -use utoipa::ToSchema; +use utoipa::{PartialSchema, ToSchema}; use super::{DeserrParseBoolError, DeserrParseIntError}; use crate::index_uid::IndexUid; @@ -30,8 +30,14 @@ use crate::tasks::{Kind, Status}; #[derive(Default, Debug, Clone, Copy)] pub struct Param(pub T); -impl<'a, T: ToSchema<'a>> ToSchema<'a> for Param { - fn schema() -> (&'a str, utoipa::openapi::RefOr) { +impl ToSchema for Param { + fn name() -> std::borrow::Cow<'static, str> { + T::name() + } +} + +impl PartialSchema for Param { + fn schema() -> utoipa::openapi::RefOr { T::schema() } } diff --git a/meilisearch-types/src/facet_values_sort.rs b/meilisearch-types/src/facet_values_sort.rs index 278061f19..8e0dd2ca4 100644 --- a/meilisearch-types/src/facet_values_sort.rs +++ b/meilisearch-types/src/facet_values_sort.rs @@ -1,8 +1,9 @@ use deserr::Deserr; use milli::OrderBy; use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; -#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Deserr)] +#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Deserr, ToSchema)] #[serde(rename_all = "camelCase")] #[deserr(rename_all = camelCase)] pub enum FacetValuesSort { diff --git a/meilisearch-types/src/locales.rs b/meilisearch-types/src/locales.rs index 8d746779e..945c38cc3 100644 --- a/meilisearch-types/src/locales.rs +++ b/meilisearch-types/src/locales.rs @@ -1,8 +1,9 @@ use deserr::Deserr; use milli::LocalizedAttributesRule; use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; -#[derive(Debug, Clone, PartialEq, Eq, Deserr, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Deserr, Serialize, Deserialize, ToSchema)] #[deserr(rename_all = camelCase)] #[serde(rename_all = "camelCase")] pub struct LocalizedAttributesRuleView { @@ -33,7 +34,7 @@ impl From for LocalizedAttributesRule { /// this enum implements `Deserr` in order to be used in the API. macro_rules! make_locale { ($(($iso_639_1:ident, $iso_639_1_str:expr) => ($iso_639_3:ident, $iso_639_3_str:expr),)+) => { - #[derive(Debug, Copy, Clone, PartialEq, Eq, Deserr, Serialize, Deserialize, Ord, PartialOrd)] + #[derive(Debug, Copy, Clone, PartialEq, Eq, Deserr, Serialize, Deserialize, Ord, PartialOrd, ToSchema)] #[deserr(rename_all = camelCase)] #[serde(rename_all = "camelCase")] pub enum Locale { diff --git a/meilisearch-types/src/settings.rs b/meilisearch-types/src/settings.rs index 2123a8e27..5531904eb 100644 --- a/meilisearch-types/src/settings.rs +++ b/meilisearch-types/src/settings.rs @@ -40,10 +40,10 @@ where .serialize(s) } -#[derive(Clone, Default, Debug, Serialize, PartialEq, Eq)] +#[derive(Clone, Default, Debug, Serialize, PartialEq, Eq, ToSchema)] pub struct Checked; -#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)] +#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, ToSchema)] pub struct Unchecked; impl Deserr for Unchecked @@ -236,6 +236,7 @@ pub struct Settings { /// Embedder required for performing meaning-based search queries. #[serde(default, skip_serializing_if = "Setting::is_not_set")] #[deserr(default, error = DeserrJsonError)] + #[schema(value_type = String)] // TODO: TAMO pub embedders: Setting>>, /// Maximum duration of a search query. #[serde(default, skip_serializing_if = "Setting::is_not_set")] @@ -244,6 +245,7 @@ pub struct Settings { pub search_cutoff_ms: Setting, #[serde(default, skip_serializing_if = "Setting::is_not_set")] #[deserr(default, error = DeserrJsonError)] + #[schema(value_type = Option>, example = json!(50))] pub localized_attributes: Setting>, #[serde(skip)] @@ -908,7 +910,7 @@ impl From for ProximityPrecision { } } -#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq, ToSchema)] +#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] pub struct WildcardSetting(Setting>); impl From>> for WildcardSetting { diff --git a/meilisearch/Cargo.toml b/meilisearch/Cargo.toml index 46a64ad24..8c74facbd 100644 --- a/meilisearch/Cargo.toml +++ b/meilisearch/Cargo.toml @@ -104,9 +104,9 @@ tracing-trace = { version = "0.1.0", path = "../tracing-trace" } tracing-actix-web = "0.7.11" build-info = { version = "1.7.0", path = "../build-info" } roaring = "0.10.2" -utoipa = { version = "5.0.0-beta.0", features = ["actix_extras", "non_strict_integers", "preserve_order", "uuid", "time", "openapi_extensions"] } -utoipa-scalar = { version = "0.2.0-beta.0", features = ["actix-web"] } -utoipa-rapidoc = { version = "4.0.1-beta.0", features = ["actix-web"] } +utoipa = { version = "5.0.0-rc.0", features = ["actix_extras", "macros", "non_strict_integers", "preserve_order", "uuid", "time", "openapi_extensions"] } +utoipa-scalar = { version = "0.2.0-rc.0", features = ["actix-web"] } +utoipa-rapidoc = { version = "4.0.1-rc.0", features = ["actix-web"] } [dev-dependencies] actix-rt = "2.10.0" diff --git a/meilisearch/src/routes/api_key.rs b/meilisearch/src/routes/api_key.rs index dd6c54e27..a167e0ea4 100644 --- a/meilisearch/src/routes/api_key.rs +++ b/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; +use super::{PaginationView, PAGINATION_DEFAULT_LIMIT}; use crate::extractors::authentication::policies::*; use crate::extractors::authentication::GuardedData; use crate::extractors::sequential_extractor::SeqHandler; @@ -134,6 +134,7 @@ impl ListApiKeys { /// Get API Keys /// /// List all API Keys +/// TODO: Tamo fix the return type #[utoipa::path( get, path = "/", @@ -141,7 +142,7 @@ impl ListApiKeys { security(("Bearer" = ["keys.get", "keys.*", "*"])), params(ListApiKeys), responses( - (status = 202, description = "List of keys", body = PaginationView, content_type = "application/json", example = json!( + (status = 202, description = "List of keys", body = serde_json::Value, content_type = "application/json", example = json!( { "results": [ { diff --git a/meilisearch/src/routes/indexes/mod.rs b/meilisearch/src/routes/indexes/mod.rs index cca017d41..b7a18ef31 100644 --- a/meilisearch/src/routes/indexes/mod.rs +++ b/meilisearch/src/routes/indexes/mod.rs @@ -256,6 +256,7 @@ pub struct IndexStats { /// Whether or not the index is currently ingesting document pub is_indexing: bool, /// Association of every field name with the number of times it occurs in the documents. + #[schema(value_type = HashMap)] pub field_distribution: FieldDistribution, } diff --git a/meilisearch/src/routes/mod.rs b/meilisearch/src/routes/mod.rs index 8837f94d9..7254cac9c 100644 --- a/meilisearch/src/routes/mod.rs +++ b/meilisearch/src/routes/mod.rs @@ -29,7 +29,6 @@ use utoipa_rapidoc::RapiDoc; use utoipa_scalar::{Scalar, Servable as ScalarServable}; use self::api_key::KeyView; -use self::api_key::ListApiKeys; use self::indexes::IndexStats; use self::logs::GetLogs; use self::logs::LogMode; @@ -63,7 +62,7 @@ pub mod tasks; ), paths(get_health, get_version, get_stats), modifiers(&OpenApiAuth), - components(schemas(PaginationView, 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(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; @@ -141,6 +140,7 @@ pub fn is_dry_run(req: &HttpRequest, opt: &Opt) -> Result { #[serde(rename_all = "camelCase")] pub struct SummarizedTaskView { /// The task unique identifier. + #[schema(value_type = u32)] task_uid: TaskId, /// The index affected by this task. May be `null` if the task is not linked to any index. index_uid: Option, @@ -171,8 +171,8 @@ pub struct Pagination { pub limit: usize, } -#[derive(Debug, Clone, Serialize, ToSchema)] -#[schema(rename_all = "camelCase")] +#[derive(Debug, Clone, Serialize)] +#[serde(rename_all = "camelCase")] pub struct PaginationView { pub results: Vec, pub offset: usize, diff --git a/milli/Cargo.toml b/milli/Cargo.toml index 5fc2d65c8..4a4de99f1 100644 --- a/milli/Cargo.toml +++ b/milli/Cargo.toml @@ -86,6 +86,7 @@ tracing = "0.1.40" ureq = { version = "2.10.0", features = ["json"] } url = "2.5.2" rayon-par-bridge = "0.1.0" +utoipa = { version = "5.0.0-rc.0", features = ["non_strict_integers", "preserve_order", "uuid", "time", "openapi_extensions"] } [dev-dependencies] mimalloc = { version = "0.1.43", default-features = false } diff --git a/milli/src/localized_attributes_rules.rs b/milli/src/localized_attributes_rules.rs index 3c421ca6b..2b9bf099c 100644 --- a/milli/src/localized_attributes_rules.rs +++ b/milli/src/localized_attributes_rules.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use charabia::Language; use serde::{Deserialize, Serialize}; +use utoipa::ToSchema; use crate::fields_ids_map::FieldsIdsMap; use crate::FieldId; @@ -14,9 +15,10 @@ use crate::FieldId; /// The pattern `attribute_name*` matches any attribute name that starts with `attribute_name`. /// The pattern `*attribute_name` matches any attribute name that ends with `attribute_name`. /// The pattern `*attribute_name*` matches any attribute name that contains `attribute_name`. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)] pub struct LocalizedAttributesRule { pub attribute_patterns: Vec, + #[schema(value_type = Vec)] pub locales: Vec, } diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 6e2b53d58..7cfff1f93 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -10,6 +10,7 @@ use itertools::{EitherOrBoth, Itertools}; use roaring::RoaringBitmap; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use time::OffsetDateTime; +use utoipa::{PartialSchema, ToSchema}; use super::del_add::DelAddOperation; use super::index_documents::{IndexDocumentsConfig, Transform}; @@ -39,6 +40,18 @@ pub enum Setting { NotSet, } +impl ToSchema for Setting { + fn name() -> std::borrow::Cow<'static, str> { + T::name() + } +} + +impl PartialSchema for Setting { + fn schema() -> utoipa::openapi::RefOr { + T::schema() + } +} + impl Deserr for Setting where T: Deserr,