bump utoipa to the latest rc and make the list key route compile

This commit is contained in:
Tamo 2024-10-09 16:23:05 +02:00
parent e9d74d424b
commit 4a1d4460bd
13 changed files with 57 additions and 28 deletions

17
Cargo.lock generated
View File

@ -3608,6 +3608,7 @@ dependencies = [
"tracing", "tracing",
"ureq", "ureq",
"url", "url",
"utoipa",
"uuid", "uuid",
] ]
@ -5847,9 +5848,9 @@ checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]] [[package]]
name = "utoipa" name = "utoipa"
version = "5.0.0-beta.0" version = "5.0.0-rc.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86fac56d240b49c629b9083c932ac20a23d926937e67c21ba209f836e2983d4f" checksum = "3cf66139459b75afa33caddb62bb2afee3838923b630b9e0ef38c369e543382f"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"serde", "serde",
@ -5859,9 +5860,9 @@ dependencies = [
[[package]] [[package]]
name = "utoipa-gen" 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" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31d88270777931b8133b119c953062bd41665bb8507841f7d433f46d2765e9d4" checksum = "7c136da726bb82a527afa1fdf3f4619eaf104e2982f071f25239cef1c67c79eb"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -5872,9 +5873,9 @@ dependencies = [
[[package]] [[package]]
name = "utoipa-rapidoc" 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" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c836d406d590721b89f572cb0379479fcfbe27f31ca65c0775265a1b9026dd34" checksum = "a4d3324d5874fb734762214827dd30b47aa78510d12abab674a97f6d7c53688f"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"serde", "serde",
@ -5884,9 +5885,9 @@ dependencies = [
[[package]] [[package]]
name = "utoipa-scalar" 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" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc86065a210b8540e46d15e0844765d1d14eec7fd6221c2b0de8f6edde990648" checksum = "7dc122c11f9642b20b3be88b60c1a3672319811f139698ac6999e72992ac7c7e"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"serde", "serde",

View File

@ -37,7 +37,7 @@ time = { version = "0.3.36", features = [
"macros", "macros",
] } ] }
tokio = "1.38" 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"] } uuid = { version = "1.10.0", features = ["serde", "v4"] }
[dev-dependencies] [dev-dependencies]

View File

@ -16,7 +16,7 @@ use std::ops::Deref;
use std::str::FromStr; use std::str::FromStr;
use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind}; use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind};
use utoipa::ToSchema; use utoipa::{PartialSchema, ToSchema};
use super::{DeserrParseBoolError, DeserrParseIntError}; use super::{DeserrParseBoolError, DeserrParseIntError};
use crate::index_uid::IndexUid; use crate::index_uid::IndexUid;
@ -30,8 +30,14 @@ use crate::tasks::{Kind, Status};
#[derive(Default, Debug, Clone, Copy)] #[derive(Default, Debug, Clone, Copy)]
pub struct Param<T>(pub T); pub struct Param<T>(pub T);
impl<'a, T: ToSchema<'a>> ToSchema<'a> for Param<T> { impl<T: ToSchema> ToSchema for Param<T> {
fn schema() -> (&'a str, utoipa::openapi::RefOr<utoipa::openapi::schema::Schema>) { fn name() -> std::borrow::Cow<'static, str> {
T::name()
}
}
impl<T: PartialSchema> PartialSchema for Param<T> {
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
T::schema() T::schema()
} }
} }

View File

@ -1,8 +1,9 @@
use deserr::Deserr; use deserr::Deserr;
use milli::OrderBy; use milli::OrderBy;
use serde::{Deserialize, Serialize}; 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")] #[serde(rename_all = "camelCase")]
#[deserr(rename_all = camelCase)] #[deserr(rename_all = camelCase)]
pub enum FacetValuesSort { pub enum FacetValuesSort {

View File

@ -1,8 +1,9 @@
use deserr::Deserr; use deserr::Deserr;
use milli::LocalizedAttributesRule; use milli::LocalizedAttributesRule;
use serde::{Deserialize, Serialize}; 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)] #[deserr(rename_all = camelCase)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct LocalizedAttributesRuleView { pub struct LocalizedAttributesRuleView {
@ -33,7 +34,7 @@ impl From<LocalizedAttributesRuleView> for LocalizedAttributesRule {
/// this enum implements `Deserr` in order to be used in the API. /// this enum implements `Deserr` in order to be used in the API.
macro_rules! make_locale { macro_rules! make_locale {
($(($iso_639_1:ident, $iso_639_1_str:expr) => ($iso_639_3:ident, $iso_639_3_str:expr),)+) => { ($(($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)] #[deserr(rename_all = camelCase)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub enum Locale { pub enum Locale {

View File

@ -40,10 +40,10 @@ where
.serialize(s) .serialize(s)
} }
#[derive(Clone, Default, Debug, Serialize, PartialEq, Eq)] #[derive(Clone, Default, Debug, Serialize, PartialEq, Eq, ToSchema)]
pub struct Checked; pub struct Checked;
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)] #[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq, ToSchema)]
pub struct Unchecked; pub struct Unchecked;
impl<E> Deserr<E> for Unchecked impl<E> Deserr<E> for Unchecked
@ -236,6 +236,7 @@ pub struct Settings<T> {
/// Embedder required for performing meaning-based search queries. /// Embedder required for performing meaning-based search queries.
#[serde(default, skip_serializing_if = "Setting::is_not_set")] #[serde(default, skip_serializing_if = "Setting::is_not_set")]
#[deserr(default, error = DeserrJsonError<InvalidSettingsEmbedders>)] #[deserr(default, error = DeserrJsonError<InvalidSettingsEmbedders>)]
#[schema(value_type = String)] // TODO: TAMO
pub embedders: Setting<BTreeMap<String, Setting<milli::vector::settings::EmbeddingSettings>>>, pub embedders: Setting<BTreeMap<String, Setting<milli::vector::settings::EmbeddingSettings>>>,
/// Maximum duration of a search query. /// Maximum duration of a search query.
#[serde(default, skip_serializing_if = "Setting::is_not_set")] #[serde(default, skip_serializing_if = "Setting::is_not_set")]
@ -244,6 +245,7 @@ pub struct Settings<T> {
pub search_cutoff_ms: Setting<u64>, pub search_cutoff_ms: Setting<u64>,
#[serde(default, skip_serializing_if = "Setting::is_not_set")] #[serde(default, skip_serializing_if = "Setting::is_not_set")]
#[deserr(default, error = DeserrJsonError<InvalidSettingsLocalizedAttributes>)] #[deserr(default, error = DeserrJsonError<InvalidSettingsLocalizedAttributes>)]
#[schema(value_type = Option<Vec<LocalizedAttributesRuleView>>, example = json!(50))]
pub localized_attributes: Setting<Vec<LocalizedAttributesRuleView>>, pub localized_attributes: Setting<Vec<LocalizedAttributesRuleView>>,
#[serde(skip)] #[serde(skip)]
@ -908,7 +910,7 @@ impl From<ProximityPrecisionView> for ProximityPrecision {
} }
} }
#[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq, ToSchema)] #[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)]
pub struct WildcardSetting(Setting<Vec<String>>); pub struct WildcardSetting(Setting<Vec<String>>);
impl From<Setting<Vec<String>>> for WildcardSetting { impl From<Setting<Vec<String>>> for WildcardSetting {

View File

@ -104,9 +104,9 @@ tracing-trace = { version = "0.1.0", path = "../tracing-trace" }
tracing-actix-web = "0.7.11" tracing-actix-web = "0.7.11"
build-info = { version = "1.7.0", path = "../build-info" } build-info = { version = "1.7.0", path = "../build-info" }
roaring = "0.10.2" roaring = "0.10.2"
utoipa = { version = "5.0.0-beta.0", features = ["actix_extras", "non_strict_integers", "preserve_order", "uuid", "time", "openapi_extensions"] } 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-beta.0", features = ["actix-web"] } utoipa-scalar = { version = "0.2.0-rc.0", features = ["actix-web"] }
utoipa-rapidoc = { version = "4.0.1-beta.0", features = ["actix-web"] } utoipa-rapidoc = { version = "4.0.1-rc.0", features = ["actix-web"] }
[dev-dependencies] [dev-dependencies]
actix-rt = "2.10.0" actix-rt = "2.10.0"

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; use super::{PaginationView, PAGINATION_DEFAULT_LIMIT};
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,6 +134,7 @@ 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 = "/",
@ -141,7 +142,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 = PaginationView<KeyView>, content_type = "application/json", example = json!( (status = 202, description = "List of keys", body = serde_json::Value, content_type = "application/json", example = json!(
{ {
"results": [ "results": [
{ {

View File

@ -256,6 +256,7 @@ pub struct IndexStats {
/// Whether or not the index is currently ingesting document /// Whether or not the index is currently ingesting document
pub is_indexing: bool, pub is_indexing: bool,
/// Association of every field name with the number of times it occurs in the documents. /// Association of every field name with the number of times it occurs in the documents.
#[schema(value_type = HashMap<String, u64>)]
pub field_distribution: FieldDistribution, pub field_distribution: FieldDistribution,
} }

View File

@ -29,7 +29,6 @@ use utoipa_rapidoc::RapiDoc;
use utoipa_scalar::{Scalar, Servable as ScalarServable}; use utoipa_scalar::{Scalar, Servable as ScalarServable};
use self::api_key::KeyView; use self::api_key::KeyView;
use self::api_key::ListApiKeys;
use self::indexes::IndexStats; use self::indexes::IndexStats;
use self::logs::GetLogs; use self::logs::GetLogs;
use self::logs::LogMode; use self::logs::LogMode;
@ -63,7 +62,7 @@ pub mod tasks;
), ),
paths(get_health, get_version, get_stats), paths(get_health, get_version, get_stats),
modifiers(&OpenApiAuth), modifiers(&OpenApiAuth),
components(schemas(PaginationView<KeyView>, 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(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;
@ -141,6 +140,7 @@ pub fn is_dry_run(req: &HttpRequest, opt: &Opt) -> Result<bool, ResponseError> {
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct SummarizedTaskView { pub struct SummarizedTaskView {
/// The task unique identifier. /// The task unique identifier.
#[schema(value_type = u32)]
task_uid: TaskId, task_uid: TaskId,
/// The index affected by this task. May be `null` if the task is not linked to any index. /// The index affected by this task. May be `null` if the task is not linked to any index.
index_uid: Option<String>, index_uid: Option<String>,
@ -171,8 +171,8 @@ pub struct Pagination {
pub limit: usize, pub limit: usize,
} }
#[derive(Debug, Clone, Serialize, ToSchema)] #[derive(Debug, Clone, Serialize)]
#[schema(rename_all = "camelCase")] #[serde(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,

View File

@ -86,6 +86,7 @@ tracing = "0.1.40"
ureq = { version = "2.10.0", features = ["json"] } ureq = { version = "2.10.0", features = ["json"] }
url = "2.5.2" url = "2.5.2"
rayon-par-bridge = "0.1.0" 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] [dev-dependencies]
mimalloc = { version = "0.1.43", default-features = false } mimalloc = { version = "0.1.43", default-features = false }

View File

@ -2,6 +2,7 @@ use std::collections::HashMap;
use charabia::Language; use charabia::Language;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use crate::fields_ids_map::FieldsIdsMap; use crate::fields_ids_map::FieldsIdsMap;
use crate::FieldId; 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 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 ends with `attribute_name`.
/// The pattern `*attribute_name*` matches any attribute name that contains `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 struct LocalizedAttributesRule {
pub attribute_patterns: Vec<String>, pub attribute_patterns: Vec<String>,
#[schema(value_type = Vec<String>)]
pub locales: Vec<Language>, pub locales: Vec<Language>,
} }

View File

@ -10,6 +10,7 @@ use itertools::{EitherOrBoth, Itertools};
use roaring::RoaringBitmap; use roaring::RoaringBitmap;
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use time::OffsetDateTime; use time::OffsetDateTime;
use utoipa::{PartialSchema, ToSchema};
use super::del_add::DelAddOperation; use super::del_add::DelAddOperation;
use super::index_documents::{IndexDocumentsConfig, Transform}; use super::index_documents::{IndexDocumentsConfig, Transform};
@ -39,6 +40,18 @@ pub enum Setting<T> {
NotSet, NotSet,
} }
impl<T: ToSchema> ToSchema for Setting<T> {
fn name() -> std::borrow::Cow<'static, str> {
T::name()
}
}
impl<T: PartialSchema> PartialSchema for Setting<T> {
fn schema() -> utoipa::openapi::RefOr<utoipa::openapi::schema::Schema> {
T::schema()
}
}
impl<T, E> Deserr<E> for Setting<T> impl<T, E> Deserr<E> for Setting<T>
where where
T: Deserr<E>, T: Deserr<E>,