From 3191316cf3ce4642e07927f0bbe358dcd2adbad0 Mon Sep 17 00:00:00 2001 From: Mubelotix Date: Thu, 17 Jul 2025 11:11:33 +0200 Subject: [PATCH] Format --- .../src/extractors/authentication/mod.rs | 4 +- .../meilisearch/src/routes/indexes/render.rs | 26 +-- .../src/routes/indexes/render_analytics.rs | 1 + .../meilisearch/tests/auth/authorization.rs | 169 ++++++++++-------- crates/meilisearch/tests/common/index.rs | 5 +- crates/meilisearch/tests/documents/mod.rs | 2 +- .../tests/documents/render_documents.rs | 118 +++--------- crates/milli/src/vector/json_template/mod.rs | 15 +- crates/milli/src/vector/mod.rs | 4 +- 9 files changed, 145 insertions(+), 199 deletions(-) diff --git a/crates/meilisearch/src/extractors/authentication/mod.rs b/crates/meilisearch/src/extractors/authentication/mod.rs index 2afbf7962..274eb2c22 100644 --- a/crates/meilisearch/src/extractors/authentication/mod.rs +++ b/crates/meilisearch/src/extractors/authentication/mod.rs @@ -138,7 +138,9 @@ pub trait Policy { auth: Data, token: &str, index: Option<&str>, - ) -> Result where Self: Sized; + ) -> Result + where + Self: Sized; } pub mod policies { diff --git a/crates/meilisearch/src/routes/indexes/render.rs b/crates/meilisearch/src/routes/indexes/render.rs index 041cb6791..d544e9a41 100644 --- a/crates/meilisearch/src/routes/indexes/render.rs +++ b/crates/meilisearch/src/routes/indexes/render.rs @@ -424,18 +424,20 @@ async fn render(index: Index, query: RenderQuery) -> Result return Err(UnknownTemplatePrefix { - embedder_name: embedder_name.to_string(), - found: found.to_string(), - available_indexing_fragments: embedding_config - .config - .embedder_options - .indexing_fragments(), - available_search_fragments: embedding_config - .config - .embedder_options - .search_fragments(), - }), + found => { + return Err(UnknownTemplatePrefix { + embedder_name: embedder_name.to_string(), + found: found.to_string(), + available_indexing_fragments: embedding_config + .config + .embedder_options + .indexing_fragments(), + available_search_fragments: embedding_config + .config + .embedder_options + .search_fragments(), + }) + } } } "chatCompletions" | "chatcompletions" => { diff --git a/crates/meilisearch/src/routes/indexes/render_analytics.rs b/crates/meilisearch/src/routes/indexes/render_analytics.rs index e69de29bb..8b1378917 100644 --- a/crates/meilisearch/src/routes/indexes/render_analytics.rs +++ b/crates/meilisearch/src/routes/indexes/render_analytics.rs @@ -0,0 +1 @@ + diff --git a/crates/meilisearch/tests/auth/authorization.rs b/crates/meilisearch/tests/auth/authorization.rs index b7794908b..9f56adee8 100644 --- a/crates/meilisearch/tests/auth/authorization.rs +++ b/crates/meilisearch/tests/auth/authorization.rs @@ -1,7 +1,7 @@ use std::collections::{HashMap, HashSet}; use ::time::format_description::well_known::Rfc3339; -use maplit::{hashmap}; +use maplit::hashmap; use meilisearch::Opt; use once_cell::sync::Lazy; use tempfile::TempDir; @@ -33,74 +33,80 @@ macro_rules! hashset { } #[allow(clippy::type_complexity)] -pub static AUTHORIZATIONS: Lazy>> = - Lazy::new(|| { - let authorizations = hashmap! { - ("POST", "/multi-search") => hashset!{"search", "*"}, - ("POST", "/indexes/products/search") => hashset!{"search", "*"}, - ("GET", "/indexes/products/search") => hashset!{"search", "*"}, - ("POST", "/indexes/products/documents") => hashset!{"documents.add", "documents.*", "*"}, - ("GET", "/indexes/products/documents") => hashset!{"documents.get", "documents.*", "*"}, - ("POST", "/indexes/products/documents/fetch") => hashset!{"documents.get", "documents.*", "*"}, - ("GET", "/indexes/products/documents/0") => hashset!{"documents.get", "documents.*", "*"}, - ("DELETE", "/indexes/products/documents/0") => hashset!{"documents.delete", "documents.*", "*"}, - ("POST", "/indexes/products/documents/delete-batch") => hashset!{"documents.delete", "documents.*", "*"}, - ("POST", "/indexes/products/documents/delete") => hashset!{"documents.delete", "documents.*", "*"}, - ("POST", "/indexes/products/render") => hashset!{["settings.get", "documents.get"], ["documents.*", "settings.get"], ["settings.*", "documents.get"], "*"}, - ("GET", "/tasks") => hashset!{"tasks.get", "tasks.*", "*"}, - ("DELETE", "/tasks") => hashset!{"tasks.delete", "tasks.*", "*"}, - ("GET", "/tasks?indexUid=products") => hashset!{"tasks.get", "tasks.*", "*"}, - ("GET", "/tasks/0") => hashset!{"tasks.get", "tasks.*", "*"}, - ("PATCH", "/indexes/products/") => hashset!{"indexes.update", "indexes.*", "*"}, - ("GET", "/indexes/products/") => hashset!{"indexes.get", "indexes.*", "*"}, - ("DELETE", "/indexes/products/") => hashset!{"indexes.delete", "indexes.*", "*"}, - ("POST", "/indexes") => hashset!{"indexes.create", "indexes.*", "*"}, - ("GET", "/indexes") => hashset!{"indexes.get", "indexes.*", "*"}, - ("POST", "/swap-indexes") => hashset!{"indexes.swap", "indexes.*", "*"}, - ("GET", "/indexes/products/settings") => hashset!{"settings.get", "settings.*", "*"}, - ("GET", "/indexes/products/settings/displayed-attributes") => hashset!{"settings.get", "settings.*", "*"}, - ("GET", "/indexes/products/settings/distinct-attribute") => hashset!{"settings.get", "settings.*", "*"}, - ("GET", "/indexes/products/settings/filterable-attributes") => hashset!{"settings.get", "settings.*", "*"}, - ("GET", "/indexes/products/settings/ranking-rules") => hashset!{"settings.get", "settings.*", "*"}, - ("GET", "/indexes/products/settings/searchable-attributes") => hashset!{"settings.get", "settings.*", "*"}, - ("GET", "/indexes/products/settings/sortable-attributes") => hashset!{"settings.get", "settings.*", "*"}, - ("GET", "/indexes/products/settings/stop-words") => hashset!{"settings.get", "settings.*", "*"}, - ("GET", "/indexes/products/settings/synonyms") => hashset!{"settings.get", "settings.*", "*"}, - ("DELETE", "/indexes/products/settings") => hashset!{"settings.update", "settings.*", "*"}, - ("PATCH", "/indexes/products/settings") => hashset!{"settings.update", "settings.*", "*"}, - ("PATCH", "/indexes/products/settings/typo-tolerance") => hashset!{"settings.update", "settings.*", "*"}, - ("PUT", "/indexes/products/settings/displayed-attributes") => hashset!{"settings.update", "settings.*", "*"}, - ("PUT", "/indexes/products/settings/distinct-attribute") => hashset!{"settings.update", "settings.*", "*"}, - ("PUT", "/indexes/products/settings/filterable-attributes") => hashset!{"settings.update", "settings.*", "*"}, - ("PUT", "/indexes/products/settings/ranking-rules") => hashset!{"settings.update", "settings.*", "*"}, - ("PUT", "/indexes/products/settings/searchable-attributes") => hashset!{"settings.update", "settings.*", "*"}, - ("PUT", "/indexes/products/settings/sortable-attributes") => hashset!{"settings.update", "settings.*", "*"}, - ("PUT", "/indexes/products/settings/stop-words") => hashset!{"settings.update", "settings.*", "*"}, - ("PUT", "/indexes/products/settings/synonyms") => hashset!{"settings.update", "settings.*", "*"}, - ("GET", "/indexes/products/stats") => hashset!{"stats.get", "stats.*", "*"}, - ("GET", "/stats") => hashset!{"stats.get", "stats.*", "*"}, - ("POST", "/dumps") => hashset!{"dumps.create", "dumps.*", "*"}, - ("POST", "/snapshots") => hashset!{"snapshots.create", "snapshots.*", "*"}, - ("GET", "/version") => hashset!{"version", "*"}, - ("GET", "/metrics") => hashset!{"metrics.get", "metrics.*", "*"}, - ("POST", "/logs/stream") => hashset!{"metrics.get", "metrics.*", "*"}, - ("DELETE", "/logs/stream") => hashset!{"metrics.get", "metrics.*", "*"}, - ("PATCH", "/keys/mykey/") => hashset!{"keys.update", "*"}, - ("GET", "/keys/mykey/") => hashset!{"keys.get", "*"}, - ("DELETE", "/keys/mykey/") => hashset!{"keys.delete", "*"}, - ("POST", "/keys") => hashset!{"keys.create", "*"}, - ("GET", "/keys") => hashset!{"keys.get", "*"}, - ("GET", "/experimental-features") => hashset!{"experimental.get", "*"}, - ("PATCH", "/experimental-features") => hashset!{"experimental.update", "*"}, - ("GET", "/network") => hashset!{"network.get", "*"}, - ("PATCH", "/network") => hashset!{"network.update", "*"}, - }; +pub static AUTHORIZATIONS: Lazy< + HashMap<(&'static str, &'static str), HashSet<&'static [&'static str]>>, +> = Lazy::new(|| { + let authorizations = hashmap! { + ("POST", "/multi-search") => hashset!{"search", "*"}, + ("POST", "/indexes/products/search") => hashset!{"search", "*"}, + ("GET", "/indexes/products/search") => hashset!{"search", "*"}, + ("POST", "/indexes/products/documents") => hashset!{"documents.add", "documents.*", "*"}, + ("GET", "/indexes/products/documents") => hashset!{"documents.get", "documents.*", "*"}, + ("POST", "/indexes/products/documents/fetch") => hashset!{"documents.get", "documents.*", "*"}, + ("GET", "/indexes/products/documents/0") => hashset!{"documents.get", "documents.*", "*"}, + ("DELETE", "/indexes/products/documents/0") => hashset!{"documents.delete", "documents.*", "*"}, + ("POST", "/indexes/products/documents/delete-batch") => hashset!{"documents.delete", "documents.*", "*"}, + ("POST", "/indexes/products/documents/delete") => hashset!{"documents.delete", "documents.*", "*"}, + ("POST", "/indexes/products/render") => hashset!{["settings.get", "documents.get"], ["documents.*", "settings.get"], ["settings.*", "documents.get"], "*"}, + ("GET", "/tasks") => hashset!{"tasks.get", "tasks.*", "*"}, + ("DELETE", "/tasks") => hashset!{"tasks.delete", "tasks.*", "*"}, + ("GET", "/tasks?indexUid=products") => hashset!{"tasks.get", "tasks.*", "*"}, + ("GET", "/tasks/0") => hashset!{"tasks.get", "tasks.*", "*"}, + ("PATCH", "/indexes/products/") => hashset!{"indexes.update", "indexes.*", "*"}, + ("GET", "/indexes/products/") => hashset!{"indexes.get", "indexes.*", "*"}, + ("DELETE", "/indexes/products/") => hashset!{"indexes.delete", "indexes.*", "*"}, + ("POST", "/indexes") => hashset!{"indexes.create", "indexes.*", "*"}, + ("GET", "/indexes") => hashset!{"indexes.get", "indexes.*", "*"}, + ("POST", "/swap-indexes") => hashset!{"indexes.swap", "indexes.*", "*"}, + ("GET", "/indexes/products/settings") => hashset!{"settings.get", "settings.*", "*"}, + ("GET", "/indexes/products/settings/displayed-attributes") => hashset!{"settings.get", "settings.*", "*"}, + ("GET", "/indexes/products/settings/distinct-attribute") => hashset!{"settings.get", "settings.*", "*"}, + ("GET", "/indexes/products/settings/filterable-attributes") => hashset!{"settings.get", "settings.*", "*"}, + ("GET", "/indexes/products/settings/ranking-rules") => hashset!{"settings.get", "settings.*", "*"}, + ("GET", "/indexes/products/settings/searchable-attributes") => hashset!{"settings.get", "settings.*", "*"}, + ("GET", "/indexes/products/settings/sortable-attributes") => hashset!{"settings.get", "settings.*", "*"}, + ("GET", "/indexes/products/settings/stop-words") => hashset!{"settings.get", "settings.*", "*"}, + ("GET", "/indexes/products/settings/synonyms") => hashset!{"settings.get", "settings.*", "*"}, + ("DELETE", "/indexes/products/settings") => hashset!{"settings.update", "settings.*", "*"}, + ("PATCH", "/indexes/products/settings") => hashset!{"settings.update", "settings.*", "*"}, + ("PATCH", "/indexes/products/settings/typo-tolerance") => hashset!{"settings.update", "settings.*", "*"}, + ("PUT", "/indexes/products/settings/displayed-attributes") => hashset!{"settings.update", "settings.*", "*"}, + ("PUT", "/indexes/products/settings/distinct-attribute") => hashset!{"settings.update", "settings.*", "*"}, + ("PUT", "/indexes/products/settings/filterable-attributes") => hashset!{"settings.update", "settings.*", "*"}, + ("PUT", "/indexes/products/settings/ranking-rules") => hashset!{"settings.update", "settings.*", "*"}, + ("PUT", "/indexes/products/settings/searchable-attributes") => hashset!{"settings.update", "settings.*", "*"}, + ("PUT", "/indexes/products/settings/sortable-attributes") => hashset!{"settings.update", "settings.*", "*"}, + ("PUT", "/indexes/products/settings/stop-words") => hashset!{"settings.update", "settings.*", "*"}, + ("PUT", "/indexes/products/settings/synonyms") => hashset!{"settings.update", "settings.*", "*"}, + ("GET", "/indexes/products/stats") => hashset!{"stats.get", "stats.*", "*"}, + ("GET", "/stats") => hashset!{"stats.get", "stats.*", "*"}, + ("POST", "/dumps") => hashset!{"dumps.create", "dumps.*", "*"}, + ("POST", "/snapshots") => hashset!{"snapshots.create", "snapshots.*", "*"}, + ("GET", "/version") => hashset!{"version", "*"}, + ("GET", "/metrics") => hashset!{"metrics.get", "metrics.*", "*"}, + ("POST", "/logs/stream") => hashset!{"metrics.get", "metrics.*", "*"}, + ("DELETE", "/logs/stream") => hashset!{"metrics.get", "metrics.*", "*"}, + ("PATCH", "/keys/mykey/") => hashset!{"keys.update", "*"}, + ("GET", "/keys/mykey/") => hashset!{"keys.get", "*"}, + ("DELETE", "/keys/mykey/") => hashset!{"keys.delete", "*"}, + ("POST", "/keys") => hashset!{"keys.create", "*"}, + ("GET", "/keys") => hashset!{"keys.get", "*"}, + ("GET", "/experimental-features") => hashset!{"experimental.get", "*"}, + ("PATCH", "/experimental-features") => hashset!{"experimental.update", "*"}, + ("GET", "/network") => hashset!{"network.get", "*"}, + ("PATCH", "/network") => hashset!{"network.update", "*"}, + }; - authorizations - }); + authorizations +}); pub static ALL_ACTIONS: Lazy> = Lazy::new(|| { - AUTHORIZATIONS.values().flat_map(|v| v.iter()).flat_map(|v| v.iter()).copied().collect::>() + AUTHORIZATIONS + .values() + .flat_map(|v| v.iter()) + .flat_map(|v| v.iter()) + .copied() + .collect::>() }); static INVALID_RESPONSE: Lazy = Lazy::new(|| { @@ -289,7 +295,7 @@ async fn unauthorized_partial_actions() { assert_eq!(202, code, "{:?}", &response); let task_id = response["taskUid"].as_u64().unwrap(); index.wait_task(task_id).await.succeeded(); - + // When multiple actions are necessary, the server mustn't accept any combination with one action missing. for ((method, route), actions) in AUTHORIZATIONS.iter() { for actions in actions { @@ -298,7 +304,11 @@ async fn unauthorized_partial_actions() { // create a new API key letting all actions except one. server.use_api_key(MASTER_KEY); - let actions = actions.iter().filter(|&a| a != excluded_action).copied().collect::>(); + let actions = actions + .iter() + .filter(|&a| a != excluded_action) + .copied() + .collect::>(); let content = json!({ "indexes": ["products"], "actions": actions, @@ -315,7 +325,14 @@ async fn unauthorized_partial_actions() { let (mut response, code) = server.dummy_request(method, route).await; response["message"] = serde_json::json!(null); - assert_eq!(response, INVALID_RESPONSE.clone(), "on route: {:?} - {:?} with actions: {:?}", method, route, actions); + assert_eq!( + response, + INVALID_RESPONSE.clone(), + "on route: {:?} - {:?} with actions: {:?}", + method, + route, + actions + ); assert_eq!(code, 403, "{:?}", &response); } } @@ -355,7 +372,11 @@ async fn access_authorized_no_index_restriction() { route, actions ); - assert_ne!(code, 403, "on route: {:?} - {:?} with action: {:?}", method, route, actions); + assert_ne!( + code, 403, + "on route: {:?} - {:?} with action: {:?}", + method, route, actions + ); } } } @@ -793,7 +814,13 @@ async fn error_creating_index_without_action() { server.use_api_key(MASTER_KEY); // create key with access on all indexes. - let create_index_actions = AUTHORIZATIONS.get(&("POST","/indexes")).unwrap().iter().flat_map(|s| s.iter()).cloned().collect::>(); + let create_index_actions = AUTHORIZATIONS + .get(&("POST", "/indexes")) + .unwrap() + .iter() + .flat_map(|s| s.iter()) + .cloned() + .collect::>(); let content = json!({ "indexes": ["*"], // Give all action but the ones allowing to create an index. diff --git a/crates/meilisearch/tests/common/index.rs b/crates/meilisearch/tests/common/index.rs index 3ff988540..44752df67 100644 --- a/crates/meilisearch/tests/common/index.rs +++ b/crates/meilisearch/tests/common/index.rs @@ -457,10 +457,7 @@ impl Index<'_, State> { self.service.get(url).await } - pub async fn render( - &self, - query: Value - ) -> (Value, StatusCode) { + pub async fn render(&self, query: Value) -> (Value, StatusCode) { let url = format!("/indexes/{}/render", urlencode(self.uid.as_ref())); self.service.post_encoded(url, query, self.encoder).await } diff --git a/crates/meilisearch/tests/documents/mod.rs b/crates/meilisearch/tests/documents/mod.rs index 78861df12..56525d5d0 100644 --- a/crates/meilisearch/tests/documents/mod.rs +++ b/crates/meilisearch/tests/documents/mod.rs @@ -2,5 +2,5 @@ mod add_documents; mod delete_documents; mod errors; mod get_documents; -mod update_documents; mod render_documents; +mod update_documents; diff --git a/crates/meilisearch/tests/documents/render_documents.rs b/crates/meilisearch/tests/documents/render_documents.rs index 766d942cb..2b97a9c00 100644 --- a/crates/meilisearch/tests/documents/render_documents.rs +++ b/crates/meilisearch/tests/documents/render_documents.rs @@ -6,13 +6,7 @@ use meili_snap::snapshot; async fn empty_id() { let index = shared_index_for_fragments().await; - let (value, code) = index - .render(json! {{ - "template": { - "id": "" - } - }}) - .await; + let (value, code) = index.render(json! {{ "template": { "id": "" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -28,13 +22,7 @@ async fn empty_id() { async fn wrong_id_prefix() { let index = shared_index_for_fragments().await; - let (value, code) = index - .render(json! {{ - "template": { - "id": "wrong.disregarded" - } - }}) - .await; + let (value, code) = index.render(json! {{ "template": { "id": "wrong.disregarded" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -50,13 +38,7 @@ async fn wrong_id_prefix() { async fn missing_embedder() { let index = shared_index_for_fragments().await; - let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders" - } - }}) - .await; + let (value, code) = index.render(json! {{ "template": { "id": "embedders" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -72,13 +54,8 @@ async fn missing_embedder() { async fn wrong_embedder() { let index = shared_index_for_fragments().await; - let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.wrong.disregarded" - } - }}) - .await; + let (value, code) = + index.render(json! {{ "template": { "id": "embedders.wrong.disregarded" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -94,13 +71,7 @@ async fn wrong_embedder() { async fn missing_template_kind() { let index = shared_index_for_fragments().await; - let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest" - } - }}) - .await; + let (value, code) = index.render(json! {{ "template": { "id": "embedders.rest" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -116,13 +87,8 @@ async fn missing_template_kind() { async fn wrong_template_kind() { let index = shared_index_for_fragments().await; - let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.wrong.disregarded" - } - }}) - .await; + let (value, code) = + index.render(json! {{ "template": { "id": "embedders.rest.wrong.disregarded" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -138,13 +104,8 @@ async fn wrong_template_kind() { async fn document_template_on_fragmented_index() { let index = shared_index_for_fragments().await; - let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.documentTemplate" - } - }}) - .await; + let (value, code) = + index.render(json! {{ "template": { "id": "embedders.rest.documentTemplate" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -160,13 +121,8 @@ async fn document_template_on_fragmented_index() { async fn missing_fragment_name() { let index = shared_index_for_fragments().await; - let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.indexingFragments" - } - }}) - .await; + let (value, code) = + index.render(json! {{ "template": { "id": "embedders.rest.indexingFragments" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -177,13 +133,8 @@ async fn missing_fragment_name() { } "#); - let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.searchFragments" - } - }}) - .await; + let (value, code) = + index.render(json! {{ "template": { "id": "embedders.rest.searchFragments" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -200,11 +151,7 @@ async fn wrong_fragment_name() { let index = shared_index_for_fragments().await; let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.indexingFragments.wrong" - } - }}) + .render(json! {{ "template": { "id": "embedders.rest.indexingFragments.wrong" }}}) .await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" @@ -216,13 +163,8 @@ async fn wrong_fragment_name() { } "#); - let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.searchFragments.wrong" - } - }}) - .await; + let (value, code) = + index.render(json! {{ "template": { "id": "embedders.rest.searchFragments.wrong" }}}).await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" { @@ -239,11 +181,9 @@ async fn leftover_tokens() { let index = shared_index_for_fragments().await; let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.indexingFragments.withBreed.leftover" - } - }}) + .render( + json! {{ "template": { "id": "embedders.rest.indexingFragments.withBreed.leftover" }}}, + ) .await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" @@ -256,11 +196,7 @@ async fn leftover_tokens() { "#); let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.searchFragments.justBreed.leftover" - } - }}) + .render(json! {{"template": { "id": "embedders.rest.searchFragments.justBreed.leftover" }}}) .await; snapshot!(code, @"400 Bad Request"); snapshot!(value, @r#" @@ -278,11 +214,7 @@ async fn fragment_retrieval() { let index = shared_index_for_fragments().await; let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.indexingFragments.withBreed" - } - }}) + .render(json! {{ "template": { "id": "embedders.rest.indexingFragments.withBreed" }}}) .await; snapshot!(code, @"200 OK"); snapshot!(value, @r#" @@ -293,11 +225,7 @@ async fn fragment_retrieval() { "#); let (value, code) = index - .render(json! {{ - "template": { - "id": "embedders.rest.searchFragments.justBreed" - } - }}) + .render(json! {{ "template": { "id": "embedders.rest.searchFragments.justBreed" }}}) .await; snapshot!(code, @"200 OK"); snapshot!(value, @r#" diff --git a/crates/milli/src/vector/json_template/mod.rs b/crates/milli/src/vector/json_template/mod.rs index 35b498633..693860575 100644 --- a/crates/milli/src/vector/json_template/mod.rs +++ b/crates/milli/src/vector/json_template/mod.rs @@ -63,10 +63,7 @@ impl Error { /// Produces an error message when the error happened at rendering time. pub fn rendering_error(&self, root: &str) -> String { if self.path.is_empty() { - format!( - "error while rendering template: {}", - &self.template_error - ) + format!("error while rendering template: {}", &self.template_error) } else { format!( "in `{}`, error while rendering template: {}", @@ -79,10 +76,7 @@ impl Error { /// Produces an error message when the error happened at parsing time. pub fn parsing_error(&self, root: &str) -> String { if self.path.is_empty() { - format!( - "error while parsing template: {}", - &self.template_error - ) + format!("error while parsing template: {}", &self.template_error) } else { format!( "in `{}`, error while parsing template: {}", @@ -153,10 +147,7 @@ impl JsonTemplate { /// If its a map, values inside can be accessed directly by their keys. pub fn render_serializable(&self, object: &T) -> Result { let object = liquid::to_object(object) - .map_err(|err| Error { - template_error: err, - path: ValuePath::new(), - })?; + .map_err(|err| Error { template_error: err, path: ValuePath::new() })?; self.render(&object) } diff --git a/crates/milli/src/vector/mod.rs b/crates/milli/src/vector/mod.rs index 07e2afecc..b312931f3 100644 --- a/crates/milli/src/vector/mod.rs +++ b/crates/milli/src/vector/mod.rs @@ -886,9 +886,7 @@ impl EmbedderOptions { | EmbedderOptions::OpenAi(_) | EmbedderOptions::Ollama(_) | EmbedderOptions::UserProvided(_) => None, - EmbedderOptions::Rest(embedder_options) => { - embedder_options.search_fragments.get(name) - } + EmbedderOptions::Rest(embedder_options) => embedder_options.search_fragments.get(name), EmbedderOptions::Composite(embedder_options) => { if let SubEmbedderOptions::Rest(embedder_options) = &embedder_options.search { embedder_options.search_fragments.get(name)