mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
Merge #3492
3492: Bump deserr r=Kerollmops a=irevoire Bump deserr to the latest version; - We now use the default actix-web extractors that deserr provides (which were copy/pasted from meilisearch) - We also use the default `JsonError` message provided by deserr instead of defining our own in meilisearch - Finally, we get the new `did you mean?` error message. Fix #3493 Co-authored-by: Tamo <tamo@meilisearch.com>
This commit is contained in:
commit
91ce8a5e67
56
Cargo.lock
generated
56
Cargo.lock
generated
@ -36,9 +36,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-http"
|
name = "actix-http"
|
||||||
version = "3.2.2"
|
version = "3.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0c83abf9903e1f0ad9973cc4f7b9767fd5a03a583f51a5b7a339e07987cd2724"
|
checksum = "0070905b2c4a98d184c4e81025253cb192aa8a73827553f38e9410801ceb35bb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
"actix-rt",
|
"actix-rt",
|
||||||
@ -46,7 +46,7 @@ dependencies = [
|
|||||||
"actix-tls",
|
"actix-tls",
|
||||||
"actix-utils",
|
"actix-utils",
|
||||||
"ahash",
|
"ahash",
|
||||||
"base64 0.13.1",
|
"base64 0.21.0",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"brotli",
|
"brotli",
|
||||||
"bytes",
|
"bytes",
|
||||||
@ -68,7 +68,10 @@ dependencies = [
|
|||||||
"rand",
|
"rand",
|
||||||
"sha1",
|
"sha1",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
"tokio",
|
||||||
|
"tokio-util",
|
||||||
"tracing",
|
"tracing",
|
||||||
|
"zstd 0.12.3+zstd.1.5.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -164,9 +167,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "actix-web"
|
name = "actix-web"
|
||||||
version = "4.2.1"
|
version = "4.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d48f7b6534e06c7bfc72ee91db7917d4af6afe23e7d223b51e68fffbb21e96b9"
|
checksum = "464e0fddc668ede5f26ec1f9557a8d44eda948732f40c6b0ad79126930eb775f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"actix-codec",
|
"actix-codec",
|
||||||
"actix-http",
|
"actix-http",
|
||||||
@ -1110,20 +1113,26 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deserr"
|
name = "deserr"
|
||||||
version = "0.3.0"
|
version = "0.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "28380303ca15ec07e1d5b079baf19cf849b09edad5cab219c1c51b2bd07523de"
|
checksum = "6eee2844f21cf7fb5693aae1fb8f1658127acfdb2fc072167d68a9152584ae64"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"actix-http",
|
||||||
|
"actix-utils",
|
||||||
|
"actix-web",
|
||||||
"deserr-internal",
|
"deserr-internal",
|
||||||
|
"futures",
|
||||||
"serde-cs",
|
"serde-cs",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serde_urlencoded",
|
||||||
|
"strsim",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "deserr-internal"
|
name = "deserr-internal"
|
||||||
version = "0.3.0"
|
version = "0.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "860928cd8af78d223a3d70dd581f21d7c3de8aa2eecd938e0c0a399ded7c1451"
|
checksum = "c27246f8ca9eeba9dd70d614b664dc43b529251ed7bd9e633131010d340da4b9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"convert_case 0.5.0",
|
"convert_case 0.5.0",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
@ -4423,7 +4432,7 @@ dependencies = [
|
|||||||
"pbkdf2",
|
"pbkdf2",
|
||||||
"sha1",
|
"sha1",
|
||||||
"time",
|
"time",
|
||||||
"zstd",
|
"zstd 0.11.2+zstd.1.5.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -4432,7 +4441,16 @@ version = "0.11.2+zstd.1.5.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4"
|
checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"zstd-safe",
|
"zstd-safe 5.0.2+zstd.1.5.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zstd"
|
||||||
|
version = "0.12.3+zstd.1.5.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806"
|
||||||
|
dependencies = [
|
||||||
|
"zstd-safe 6.0.4+zstd.1.5.4",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -4446,10 +4464,20 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zstd-sys"
|
name = "zstd-safe"
|
||||||
version = "2.0.5+zstd.1.5.2"
|
version = "6.0.4+zstd.1.5.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "edc50ffce891ad571e9f9afe5039c4837bede781ac4bb13052ed7ae695518596"
|
checksum = "7afb4b54b8910cf5447638cb54bf4e8a65cbedd783af98b98c62ffe91f185543"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"zstd-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zstd-sys"
|
||||||
|
version = "2.0.7+zstd.1.5.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -9,7 +9,7 @@ actix-web = { version = "4.2.1", default-features = false }
|
|||||||
anyhow = "1.0.65"
|
anyhow = "1.0.65"
|
||||||
convert_case = "0.6.0"
|
convert_case = "0.6.0"
|
||||||
csv = "1.1.6"
|
csv = "1.1.6"
|
||||||
deserr = "0.3.0"
|
deserr = "0.4.1"
|
||||||
either = { version = "1.6.1", features = ["serde"] }
|
either = { version = "1.6.1", features = ["serde"] }
|
||||||
enum-iterator = "1.1.3"
|
enum-iterator = "1.1.3"
|
||||||
file-store = { path = "../file-store" }
|
file-store = { path = "../file-store" }
|
||||||
|
@ -1,328 +0,0 @@
|
|||||||
/*!
|
|
||||||
This module implements the error messages of deserialization errors.
|
|
||||||
|
|
||||||
We try to:
|
|
||||||
1. Give a human-readable description of where the error originated.
|
|
||||||
2. Use the correct terms depending on the format of the request (json/query param)
|
|
||||||
3. Categorise the type of the error (e.g. missing field, wrong value type, unexpected error, etc.)
|
|
||||||
*/
|
|
||||||
use deserr::{ErrorKind, IntoValue, ValueKind, ValuePointerRef};
|
|
||||||
|
|
||||||
use super::{DeserrJsonError, DeserrQueryParamError};
|
|
||||||
use crate::error::{Code, ErrorCode};
|
|
||||||
|
|
||||||
/// Return a description of the given location in a Json, preceded by the given article.
|
|
||||||
/// e.g. `at .key1[8].key2`. If the location is the origin, the given article will not be
|
|
||||||
/// included in the description.
|
|
||||||
pub fn location_json_description(location: ValuePointerRef, article: &str) -> String {
|
|
||||||
fn rec(location: ValuePointerRef) -> String {
|
|
||||||
match location {
|
|
||||||
ValuePointerRef::Origin => String::new(),
|
|
||||||
ValuePointerRef::Key { key, prev } => rec(*prev) + "." + key,
|
|
||||||
ValuePointerRef::Index { index, prev } => format!("{}[{index}]", rec(*prev)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
match location {
|
|
||||||
ValuePointerRef::Origin => String::new(),
|
|
||||||
_ => {
|
|
||||||
format!("{article} `{}`", rec(location))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return a description of the list of value kinds for a Json payload.
|
|
||||||
fn value_kinds_description_json(kinds: &[ValueKind]) -> String {
|
|
||||||
// Rank each value kind so that they can be sorted (and deduplicated)
|
|
||||||
// Having a predictable order helps with pattern matching
|
|
||||||
fn order(kind: &ValueKind) -> u8 {
|
|
||||||
match kind {
|
|
||||||
ValueKind::Null => 0,
|
|
||||||
ValueKind::Boolean => 1,
|
|
||||||
ValueKind::Integer => 2,
|
|
||||||
ValueKind::NegativeInteger => 3,
|
|
||||||
ValueKind::Float => 4,
|
|
||||||
ValueKind::String => 5,
|
|
||||||
ValueKind::Sequence => 6,
|
|
||||||
ValueKind::Map => 7,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Return a description of a single value kind, preceded by an article
|
|
||||||
fn single_description(kind: &ValueKind) -> &'static str {
|
|
||||||
match kind {
|
|
||||||
ValueKind::Null => "null",
|
|
||||||
ValueKind::Boolean => "a boolean",
|
|
||||||
ValueKind::Integer => "a positive integer",
|
|
||||||
ValueKind::NegativeInteger => "a negative integer",
|
|
||||||
ValueKind::Float => "a number",
|
|
||||||
ValueKind::String => "a string",
|
|
||||||
ValueKind::Sequence => "an array",
|
|
||||||
ValueKind::Map => "an object",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn description_rec(kinds: &[ValueKind], count_items: &mut usize, message: &mut String) {
|
|
||||||
let (msg_part, rest): (_, &[ValueKind]) = match kinds {
|
|
||||||
[] => (String::new(), &[]),
|
|
||||||
[ValueKind::Integer | ValueKind::NegativeInteger, ValueKind::Float, rest @ ..] => {
|
|
||||||
("a number".to_owned(), rest)
|
|
||||||
}
|
|
||||||
[ValueKind::Integer, ValueKind::NegativeInteger, ValueKind::Float, rest @ ..] => {
|
|
||||||
("a number".to_owned(), rest)
|
|
||||||
}
|
|
||||||
[ValueKind::Integer, ValueKind::NegativeInteger, rest @ ..] => {
|
|
||||||
("an integer".to_owned(), rest)
|
|
||||||
}
|
|
||||||
[a] => (single_description(a).to_owned(), &[]),
|
|
||||||
[a, rest @ ..] => (single_description(a).to_owned(), rest),
|
|
||||||
};
|
|
||||||
|
|
||||||
if rest.is_empty() {
|
|
||||||
if *count_items == 0 {
|
|
||||||
message.push_str(&msg_part);
|
|
||||||
} else if *count_items == 1 {
|
|
||||||
message.push_str(&format!(" or {msg_part}"));
|
|
||||||
} else {
|
|
||||||
message.push_str(&format!(", or {msg_part}"));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if *count_items == 0 {
|
|
||||||
message.push_str(&msg_part);
|
|
||||||
} else {
|
|
||||||
message.push_str(&format!(", {msg_part}"));
|
|
||||||
}
|
|
||||||
|
|
||||||
*count_items += 1;
|
|
||||||
description_rec(rest, count_items, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut kinds = kinds.to_owned();
|
|
||||||
kinds.sort_by_key(order);
|
|
||||||
kinds.dedup();
|
|
||||||
|
|
||||||
if kinds.is_empty() {
|
|
||||||
// Should not happen ideally
|
|
||||||
"a different value".to_owned()
|
|
||||||
} else {
|
|
||||||
let mut message = String::new();
|
|
||||||
description_rec(kinds.as_slice(), &mut 0, &mut message);
|
|
||||||
message
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return the JSON string of the value preceded by a description of its kind
|
|
||||||
fn value_description_with_kind_json(v: &serde_json::Value) -> String {
|
|
||||||
match v.kind() {
|
|
||||||
ValueKind::Null => "null".to_owned(),
|
|
||||||
kind => {
|
|
||||||
format!(
|
|
||||||
"{}: `{}`",
|
|
||||||
value_kinds_description_json(&[kind]),
|
|
||||||
serde_json::to_string(v).unwrap()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C: Default + ErrorCode> deserr::DeserializeError for DeserrJsonError<C> {
|
|
||||||
fn error<V: IntoValue>(
|
|
||||||
_self_: Option<Self>,
|
|
||||||
error: deserr::ErrorKind<V>,
|
|
||||||
location: ValuePointerRef,
|
|
||||||
) -> Result<Self, Self> {
|
|
||||||
let mut message = String::new();
|
|
||||||
|
|
||||||
message.push_str(&match error {
|
|
||||||
ErrorKind::IncorrectValueKind { actual, accepted } => {
|
|
||||||
let expected = value_kinds_description_json(accepted);
|
|
||||||
let received = value_description_with_kind_json(&serde_json::Value::from(actual));
|
|
||||||
|
|
||||||
let location = location_json_description(location, " at");
|
|
||||||
|
|
||||||
format!("Invalid value type{location}: expected {expected}, but found {received}")
|
|
||||||
}
|
|
||||||
ErrorKind::MissingField { field } => {
|
|
||||||
let location = location_json_description(location, " inside");
|
|
||||||
format!("Missing field `{field}`{location}")
|
|
||||||
}
|
|
||||||
ErrorKind::UnknownKey { key, accepted } => {
|
|
||||||
let location = location_json_description(location, " inside");
|
|
||||||
format!(
|
|
||||||
"Unknown field `{}`{location}: expected one of {}",
|
|
||||||
key,
|
|
||||||
accepted
|
|
||||||
.iter()
|
|
||||||
.map(|accepted| format!("`{}`", accepted))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(", ")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ErrorKind::UnknownValue { value, accepted } => {
|
|
||||||
let location = location_json_description(location, " at");
|
|
||||||
format!(
|
|
||||||
"Unknown value `{}`{location}: expected one of {}",
|
|
||||||
value,
|
|
||||||
accepted
|
|
||||||
.iter()
|
|
||||||
.map(|accepted| format!("`{}`", accepted))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(", "),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ErrorKind::Unexpected { msg } => {
|
|
||||||
let location = location_json_description(location, " at");
|
|
||||||
format!("Invalid value{location}: {msg}")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Err(DeserrJsonError::new(message, C::default().error_code()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn immutable_field_error(field: &str, accepted: &[&str], code: Code) -> DeserrJsonError {
|
|
||||||
let msg = format!(
|
|
||||||
"Immutable field `{field}`: expected one of {}",
|
|
||||||
accepted
|
|
||||||
.iter()
|
|
||||||
.map(|accepted| format!("`{}`", accepted))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(", ")
|
|
||||||
);
|
|
||||||
|
|
||||||
DeserrJsonError::new(msg, code)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return a description of the given location in query parameters, preceded by the
|
|
||||||
/// given article. e.g. `at key5[2]`. If the location is the origin, the given article
|
|
||||||
/// will not be included in the description.
|
|
||||||
pub fn location_query_param_description(location: ValuePointerRef, article: &str) -> String {
|
|
||||||
fn rec(location: ValuePointerRef) -> String {
|
|
||||||
match location {
|
|
||||||
ValuePointerRef::Origin => String::new(),
|
|
||||||
ValuePointerRef::Key { key, prev } => {
|
|
||||||
if matches!(prev, ValuePointerRef::Origin) {
|
|
||||||
key.to_owned()
|
|
||||||
} else {
|
|
||||||
rec(*prev) + "." + key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ValuePointerRef::Index { index, prev } => format!("{}[{index}]", rec(*prev)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
match location {
|
|
||||||
ValuePointerRef::Origin => String::new(),
|
|
||||||
_ => {
|
|
||||||
format!("{article} `{}`", rec(location))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<C: Default + ErrorCode> deserr::DeserializeError for DeserrQueryParamError<C> {
|
|
||||||
fn error<V: IntoValue>(
|
|
||||||
_self_: Option<Self>,
|
|
||||||
error: deserr::ErrorKind<V>,
|
|
||||||
location: ValuePointerRef,
|
|
||||||
) -> Result<Self, Self> {
|
|
||||||
let mut message = String::new();
|
|
||||||
|
|
||||||
message.push_str(&match error {
|
|
||||||
ErrorKind::IncorrectValueKind { actual, accepted } => {
|
|
||||||
let expected = value_kinds_description_query_param(accepted);
|
|
||||||
let received = value_description_with_kind_query_param(actual);
|
|
||||||
|
|
||||||
let location = location_query_param_description(location, " for parameter");
|
|
||||||
|
|
||||||
format!("Invalid value type{location}: expected {expected}, but found {received}")
|
|
||||||
}
|
|
||||||
ErrorKind::MissingField { field } => {
|
|
||||||
let location = location_query_param_description(location, " inside");
|
|
||||||
format!("Missing parameter `{field}`{location}")
|
|
||||||
}
|
|
||||||
ErrorKind::UnknownKey { key, accepted } => {
|
|
||||||
let location = location_query_param_description(location, " inside");
|
|
||||||
format!(
|
|
||||||
"Unknown parameter `{}`{location}: expected one of {}",
|
|
||||||
key,
|
|
||||||
accepted
|
|
||||||
.iter()
|
|
||||||
.map(|accepted| format!("`{}`", accepted))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(", ")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ErrorKind::UnknownValue { value, accepted } => {
|
|
||||||
let location = location_query_param_description(location, " for parameter");
|
|
||||||
format!(
|
|
||||||
"Unknown value `{}`{location}: expected one of {}",
|
|
||||||
value,
|
|
||||||
accepted
|
|
||||||
.iter()
|
|
||||||
.map(|accepted| format!("`{}`", accepted))
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(", "),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
ErrorKind::Unexpected { msg } => {
|
|
||||||
let location = location_query_param_description(location, " in parameter");
|
|
||||||
format!("Invalid value{location}: {msg}")
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Err(DeserrQueryParamError::new(message, C::default().error_code()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Return a description of the list of value kinds for query parameters
|
|
||||||
/// Since query parameters are always treated as strings, we always return
|
|
||||||
/// "a string" for now.
|
|
||||||
fn value_kinds_description_query_param(_accepted: &[ValueKind]) -> String {
|
|
||||||
"a string".to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn value_description_with_kind_query_param<V: IntoValue>(actual: deserr::Value<V>) -> String {
|
|
||||||
match actual {
|
|
||||||
deserr::Value::Null => "null".to_owned(),
|
|
||||||
deserr::Value::Boolean(x) => format!("a boolean: `{x}`"),
|
|
||||||
deserr::Value::Integer(x) => format!("an integer: `{x}`"),
|
|
||||||
deserr::Value::NegativeInteger(x) => {
|
|
||||||
format!("an integer: `{x}`")
|
|
||||||
}
|
|
||||||
deserr::Value::Float(x) => {
|
|
||||||
format!("a number: `{x}`")
|
|
||||||
}
|
|
||||||
deserr::Value::String(x) => {
|
|
||||||
format!("a string: `{x}`")
|
|
||||||
}
|
|
||||||
deserr::Value::Sequence(_) => "multiple values".to_owned(),
|
|
||||||
deserr::Value::Map(_) => "multiple parameters".to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use deserr::ValueKind;
|
|
||||||
|
|
||||||
use crate::deserr::error_messages::value_kinds_description_json;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_value_kinds_description_json() {
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[]), @"a different value");
|
|
||||||
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Boolean]), @"a boolean");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Integer]), @"a positive integer");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::NegativeInteger]), @"a negative integer");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Integer]), @"a positive integer");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::String]), @"a string");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Sequence]), @"an array");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Map]), @"an object");
|
|
||||||
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Integer, ValueKind::Boolean]), @"a boolean or a positive integer");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Null, ValueKind::Integer]), @"null or a positive integer");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Sequence, ValueKind::NegativeInteger]), @"a negative integer or an array");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Integer, ValueKind::Float]), @"a number");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Integer, ValueKind::Float, ValueKind::NegativeInteger]), @"a number");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Integer, ValueKind::Float, ValueKind::NegativeInteger, ValueKind::Null]), @"null or a number");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Boolean, ValueKind::Integer, ValueKind::Float, ValueKind::NegativeInteger, ValueKind::Null]), @"null, a boolean, or a number");
|
|
||||||
insta::assert_display_snapshot!(value_kinds_description_json(&[ValueKind::Null, ValueKind::Boolean, ValueKind::Integer, ValueKind::Float, ValueKind::NegativeInteger, ValueKind::Null]), @"null, a boolean, or a number");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +1,19 @@
|
|||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use std::ops::ControlFlow;
|
||||||
|
|
||||||
use deserr::{DeserializeError, MergeWithError, ValuePointerRef};
|
use deserr::errors::{JsonError, QueryParamError};
|
||||||
|
use deserr::{take_cf_content, DeserializeError, IntoValue, MergeWithError, ValuePointerRef};
|
||||||
|
|
||||||
use crate::error::deserr_codes::{self, *};
|
use crate::error::deserr_codes::*;
|
||||||
use crate::error::{
|
use crate::error::{
|
||||||
unwrap_any, Code, DeserrParseBoolError, DeserrParseIntError, ErrorCode, InvalidTaskDateError,
|
Code, DeserrParseBoolError, DeserrParseIntError, ErrorCode, InvalidTaskDateError,
|
||||||
ParseOffsetDateTimeError,
|
ParseOffsetDateTimeError,
|
||||||
};
|
};
|
||||||
use crate::index_uid::IndexUidFormatError;
|
use crate::index_uid::IndexUidFormatError;
|
||||||
use crate::tasks::{ParseTaskKindError, ParseTaskStatusError};
|
use crate::tasks::{ParseTaskKindError, ParseTaskStatusError};
|
||||||
|
|
||||||
pub mod error_messages;
|
|
||||||
pub mod query_params;
|
pub mod query_params;
|
||||||
|
|
||||||
/// Marker type for the Json format
|
/// Marker type for the Json format
|
||||||
@ -20,8 +21,8 @@ pub struct DeserrJson;
|
|||||||
/// Marker type for the Query Parameter format
|
/// Marker type for the Query Parameter format
|
||||||
pub struct DeserrQueryParam;
|
pub struct DeserrQueryParam;
|
||||||
|
|
||||||
pub type DeserrJsonError<C = deserr_codes::BadRequest> = DeserrError<DeserrJson, C>;
|
pub type DeserrJsonError<C = BadRequest> = DeserrError<DeserrJson, C>;
|
||||||
pub type DeserrQueryParamError<C = deserr_codes::BadRequest> = DeserrError<DeserrQueryParam, C>;
|
pub type DeserrQueryParamError<C = BadRequest> = DeserrError<DeserrQueryParam, C>;
|
||||||
|
|
||||||
/// A request deserialization error.
|
/// A request deserialization error.
|
||||||
///
|
///
|
||||||
@ -37,6 +38,7 @@ impl<Format, C: Default + ErrorCode> DeserrError<Format, C> {
|
|||||||
Self { msg, code, _phantom: PhantomData }
|
Self { msg, code, _phantom: PhantomData }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Format, C: Default + ErrorCode> std::fmt::Debug for DeserrError<Format, C> {
|
impl<Format, C: Default + ErrorCode> std::fmt::Debug for DeserrError<Format, C> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.debug_struct("DeserrError").field("msg", &self.msg).field("code", &self.code).finish()
|
f.debug_struct("DeserrError").field("msg", &self.msg).field("code", &self.code).finish()
|
||||||
@ -49,6 +51,16 @@ impl<Format, C: Default + ErrorCode> std::fmt::Display for DeserrError<Format, C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<F, C: Default + ErrorCode> actix_web::ResponseError for DeserrError<F, C> {
|
||||||
|
fn status_code(&self) -> actix_web::http::StatusCode {
|
||||||
|
self.code.http()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn error_response(&self) -> actix_web::HttpResponse<actix_web::body::BoxBody> {
|
||||||
|
crate::error::ResponseError::from_msg(self.msg.to_string(), self.code).error_response()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<Format, C: Default + ErrorCode> std::error::Error for DeserrError<Format, C> {}
|
impl<Format, C: Default + ErrorCode> std::error::Error for DeserrError<Format, C> {}
|
||||||
impl<Format, C: Default + ErrorCode> ErrorCode for DeserrError<Format, C> {
|
impl<Format, C: Default + ErrorCode> ErrorCode for DeserrError<Format, C> {
|
||||||
fn error_code(&self) -> Code {
|
fn error_code(&self) -> Code {
|
||||||
@ -64,8 +76,8 @@ impl<Format, C1: Default + ErrorCode, C2: Default + ErrorCode>
|
|||||||
_self_: Option<Self>,
|
_self_: Option<Self>,
|
||||||
other: DeserrError<Format, C2>,
|
other: DeserrError<Format, C2>,
|
||||||
_merge_location: ValuePointerRef,
|
_merge_location: ValuePointerRef,
|
||||||
) -> Result<Self, Self> {
|
) -> ControlFlow<Self, Self> {
|
||||||
Err(DeserrError { msg: other.msg, code: other.code, _phantom: PhantomData })
|
ControlFlow::Break(DeserrError { msg: other.msg, code: other.code, _phantom: PhantomData })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,17 +86,56 @@ impl<Format, C: Default + ErrorCode> MergeWithError<Infallible> for DeserrError<
|
|||||||
_self_: Option<Self>,
|
_self_: Option<Self>,
|
||||||
_other: Infallible,
|
_other: Infallible,
|
||||||
_merge_location: ValuePointerRef,
|
_merge_location: ValuePointerRef,
|
||||||
) -> Result<Self, Self> {
|
) -> ControlFlow<Self, Self> {
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<C: Default + ErrorCode> DeserializeError for DeserrJsonError<C> {
|
||||||
|
fn error<V: IntoValue>(
|
||||||
|
_self_: Option<Self>,
|
||||||
|
error: deserr::ErrorKind<V>,
|
||||||
|
location: ValuePointerRef,
|
||||||
|
) -> ControlFlow<Self, Self> {
|
||||||
|
ControlFlow::Break(DeserrJsonError::new(
|
||||||
|
take_cf_content(JsonError::error(None, error, location)).to_string(),
|
||||||
|
C::default().error_code(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<C: Default + ErrorCode> DeserializeError for DeserrQueryParamError<C> {
|
||||||
|
fn error<V: IntoValue>(
|
||||||
|
_self_: Option<Self>,
|
||||||
|
error: deserr::ErrorKind<V>,
|
||||||
|
location: ValuePointerRef,
|
||||||
|
) -> ControlFlow<Self, Self> {
|
||||||
|
ControlFlow::Break(DeserrQueryParamError::new(
|
||||||
|
take_cf_content(QueryParamError::error(None, error, location)).to_string(),
|
||||||
|
C::default().error_code(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn immutable_field_error(field: &str, accepted: &[&str], code: Code) -> DeserrJsonError {
|
||||||
|
let msg = format!(
|
||||||
|
"Immutable field `{field}`: expected one of {}",
|
||||||
|
accepted
|
||||||
|
.iter()
|
||||||
|
.map(|accepted| format!("`{}`", accepted))
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(", ")
|
||||||
|
);
|
||||||
|
|
||||||
|
DeserrJsonError::new(msg, code)
|
||||||
|
}
|
||||||
|
|
||||||
// Implement a convenience function to build a `missing_field` error
|
// Implement a convenience function to build a `missing_field` error
|
||||||
macro_rules! make_missing_field_convenience_builder {
|
macro_rules! make_missing_field_convenience_builder {
|
||||||
($err_code:ident, $fn_name:ident) => {
|
($err_code:ident, $fn_name:ident) => {
|
||||||
impl DeserrJsonError<$err_code> {
|
impl DeserrJsonError<$err_code> {
|
||||||
pub fn $fn_name(field: &str, location: ValuePointerRef) -> Self {
|
pub fn $fn_name(field: &str, location: ValuePointerRef) -> Self {
|
||||||
let x = unwrap_any(Self::error::<Infallible>(
|
let x = deserr::take_cf_content(Self::error::<Infallible>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::MissingField { field },
|
deserr::ErrorKind::MissingField { field },
|
||||||
location,
|
location,
|
||||||
@ -112,7 +163,7 @@ macro_rules! merge_with_error_impl_take_error_message {
|
|||||||
_self_: Option<Self>,
|
_self_: Option<Self>,
|
||||||
other: $err_type,
|
other: $err_type,
|
||||||
merge_location: ValuePointerRef,
|
merge_location: ValuePointerRef,
|
||||||
) -> Result<Self, Self> {
|
) -> ControlFlow<Self, Self> {
|
||||||
DeserrError::<Format, C>::error::<Infallible>(
|
DeserrError::<Format, C>::error::<Infallible>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::Unexpected { msg: other.to_string() },
|
deserr::ErrorKind::Unexpected { msg: other.to_string() },
|
||||||
|
@ -15,10 +15,9 @@ use std::convert::Infallible;
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValueKind};
|
use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind};
|
||||||
|
|
||||||
use super::{DeserrParseBoolError, DeserrParseIntError};
|
use super::{DeserrParseBoolError, DeserrParseIntError};
|
||||||
use crate::error::unwrap_any;
|
|
||||||
use crate::index_uid::IndexUid;
|
use crate::index_uid::IndexUid;
|
||||||
use crate::tasks::{Kind, Status};
|
use crate::tasks::{Kind, Status};
|
||||||
|
|
||||||
@ -38,7 +37,7 @@ impl<T> Deref for Param<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> DeserializeFromValue<E> for Param<T>
|
impl<T, E> Deserr<E> for Param<T>
|
||||||
where
|
where
|
||||||
E: DeserializeError + MergeWithError<T::Err>,
|
E: DeserializeError + MergeWithError<T::Err>,
|
||||||
T: FromQueryParameter,
|
T: FromQueryParameter,
|
||||||
@ -50,9 +49,9 @@ where
|
|||||||
match value {
|
match value {
|
||||||
deserr::Value::String(s) => match T::from_query_param(&s) {
|
deserr::Value::String(s) => match T::from_query_param(&s) {
|
||||||
Ok(x) => Ok(Param(x)),
|
Ok(x) => Ok(Param(x)),
|
||||||
Err(e) => Err(unwrap_any(E::merge(None, e, location))),
|
Err(e) => Err(deserr::take_cf_content(E::merge(None, e, location))),
|
||||||
},
|
},
|
||||||
_ => Err(unwrap_any(E::error(
|
_ => Err(deserr::take_cf_content(E::error(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::IncorrectValueKind {
|
deserr::ErrorKind::IncorrectValueKind {
|
||||||
actual: value,
|
actual: value,
|
||||||
|
@ -127,7 +127,7 @@ macro_rules! make_error_codes {
|
|||||||
}
|
}
|
||||||
impl Code {
|
impl Code {
|
||||||
/// return the HTTP status code associated with the `Code`
|
/// return the HTTP status code associated with the `Code`
|
||||||
fn http(&self) -> StatusCode {
|
pub fn http(&self) -> StatusCode {
|
||||||
match self {
|
match self {
|
||||||
$(
|
$(
|
||||||
Code::$code_ident => StatusCode::$status
|
Code::$code_ident => StatusCode::$status
|
||||||
@ -381,14 +381,6 @@ impl ErrorCode for io::Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unwrap a result, either its Ok or Err value.
|
|
||||||
pub fn unwrap_any<T>(any: Result<T, T>) -> T {
|
|
||||||
match any {
|
|
||||||
Ok(any) => any,
|
|
||||||
Err(any) => any,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deserialization when `deserr` cannot parse an API key date.
|
/// Deserialization when `deserr` cannot parse an API key date.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ParseOffsetDateTimeError(pub String);
|
pub struct ParseOffsetDateTimeError(pub String);
|
||||||
|
@ -2,14 +2,14 @@ use std::error::Error;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use deserr::DeserializeFromValue;
|
use deserr::Deserr;
|
||||||
|
|
||||||
use crate::error::{Code, ErrorCode};
|
use crate::error::{Code, ErrorCode};
|
||||||
|
|
||||||
/// An index uid is composed of only ascii alphanumeric characters, - and _, between 1 and 400
|
/// An index uid is composed of only ascii alphanumeric characters, - and _, between 1 and 400
|
||||||
/// bytes long
|
/// bytes long
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, DeserializeFromValue)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserr)]
|
||||||
#[deserr(from(String) = IndexUid::try_from -> IndexUidFormatError)]
|
#[deserr(try_from(String) = IndexUid::try_from -> IndexUidFormatError)]
|
||||||
pub struct IndexUid(String);
|
pub struct IndexUid(String);
|
||||||
|
|
||||||
impl IndexUid {
|
impl IndexUid {
|
||||||
|
@ -4,7 +4,7 @@ use std::fmt;
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use deserr::DeserializeFromValue;
|
use deserr::Deserr;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::error::{Code, ErrorCode};
|
use crate::error::{Code, ErrorCode};
|
||||||
@ -12,8 +12,8 @@ use crate::index_uid::{IndexUid, IndexUidFormatError};
|
|||||||
|
|
||||||
/// An index uid pattern is composed of only ascii alphanumeric characters, - and _, between 1 and 400
|
/// An index uid pattern is composed of only ascii alphanumeric characters, - and _, between 1 and 400
|
||||||
/// bytes long and optionally ending with a *.
|
/// bytes long and optionally ending with a *.
|
||||||
#[derive(Serialize, Deserialize, DeserializeFromValue, Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Serialize, Deserialize, Deserr, Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
#[deserr(from(&String) = FromStr::from_str -> IndexUidPatternFormatError)]
|
#[deserr(try_from(&String) = FromStr::from_str -> IndexUidPatternFormatError)]
|
||||||
pub struct IndexUidPattern(String);
|
pub struct IndexUidPattern(String);
|
||||||
|
|
||||||
impl IndexUidPattern {
|
impl IndexUidPattern {
|
||||||
|
@ -2,7 +2,7 @@ use std::convert::Infallible;
|
|||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValuePointerRef};
|
use deserr::{DeserializeError, Deserr, MergeWithError, ValuePointerRef};
|
||||||
use enum_iterator::Sequence;
|
use enum_iterator::Sequence;
|
||||||
use milli::update::Setting;
|
use milli::update::Setting;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -11,10 +11,9 @@ use time::macros::{format_description, time};
|
|||||||
use time::{Date, OffsetDateTime, PrimitiveDateTime};
|
use time::{Date, OffsetDateTime, PrimitiveDateTime};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::deserr::error_messages::immutable_field_error;
|
use crate::deserr::{immutable_field_error, DeserrError, DeserrJsonError};
|
||||||
use crate::deserr::{DeserrError, DeserrJsonError};
|
|
||||||
use crate::error::deserr_codes::*;
|
use crate::error::deserr_codes::*;
|
||||||
use crate::error::{unwrap_any, Code, ErrorCode, ParseOffsetDateTimeError};
|
use crate::error::{Code, ErrorCode, ParseOffsetDateTimeError};
|
||||||
use crate::index_uid_pattern::{IndexUidPattern, IndexUidPatternFormatError};
|
use crate::index_uid_pattern::{IndexUidPattern, IndexUidPatternFormatError};
|
||||||
|
|
||||||
pub type KeyId = Uuid;
|
pub type KeyId = Uuid;
|
||||||
@ -24,7 +23,7 @@ impl<C: Default + ErrorCode> MergeWithError<IndexUidPatternFormatError> for Dese
|
|||||||
_self_: Option<Self>,
|
_self_: Option<Self>,
|
||||||
other: IndexUidPatternFormatError,
|
other: IndexUidPatternFormatError,
|
||||||
merge_location: deserr::ValuePointerRef,
|
merge_location: deserr::ValuePointerRef,
|
||||||
) -> std::result::Result<Self, Self> {
|
) -> std::ops::ControlFlow<Self, Self> {
|
||||||
DeserrError::error::<Infallible>(
|
DeserrError::error::<Infallible>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::Unexpected { msg: other.to_string() },
|
deserr::ErrorKind::Unexpected { msg: other.to_string() },
|
||||||
@ -33,20 +32,20 @@ impl<C: Default + ErrorCode> MergeWithError<IndexUidPatternFormatError> for Dese
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, DeserializeFromValue)]
|
#[derive(Debug, Deserr)]
|
||||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct CreateApiKey {
|
pub struct CreateApiKey {
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidApiKeyDescription>)]
|
#[deserr(default, error = DeserrJsonError<InvalidApiKeyDescription>)]
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidApiKeyName>)]
|
#[deserr(default, error = DeserrJsonError<InvalidApiKeyName>)]
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
#[deserr(default = Uuid::new_v4(), error = DeserrJsonError<InvalidApiKeyUid>, from(&String) = Uuid::from_str -> uuid::Error)]
|
#[deserr(default = Uuid::new_v4(), error = DeserrJsonError<InvalidApiKeyUid>, try_from(&String) = Uuid::from_str -> uuid::Error)]
|
||||||
pub uid: KeyId,
|
pub uid: KeyId,
|
||||||
#[deserr(error = DeserrJsonError<InvalidApiKeyActions>, missing_field_error = DeserrJsonError::missing_api_key_actions)]
|
#[deserr(error = DeserrJsonError<InvalidApiKeyActions>, missing_field_error = DeserrJsonError::missing_api_key_actions)]
|
||||||
pub actions: Vec<Action>,
|
pub actions: Vec<Action>,
|
||||||
#[deserr(error = DeserrJsonError<InvalidApiKeyIndexes>, missing_field_error = DeserrJsonError::missing_api_key_indexes)]
|
#[deserr(error = DeserrJsonError<InvalidApiKeyIndexes>, missing_field_error = DeserrJsonError::missing_api_key_indexes)]
|
||||||
pub indexes: Vec<IndexUidPattern>,
|
pub indexes: Vec<IndexUidPattern>,
|
||||||
#[deserr(error = DeserrJsonError<InvalidApiKeyExpiresAt>, from(Option<String>) = parse_expiration_date -> ParseOffsetDateTimeError, missing_field_error = DeserrJsonError::missing_api_key_expires_at)]
|
#[deserr(error = DeserrJsonError<InvalidApiKeyExpiresAt>, try_from(Option<String>) = parse_expiration_date -> ParseOffsetDateTimeError, missing_field_error = DeserrJsonError::missing_api_key_expires_at)]
|
||||||
pub expires_at: Option<OffsetDateTime>,
|
pub expires_at: Option<OffsetDateTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +78,7 @@ fn deny_immutable_fields_api_key(
|
|||||||
"expiresAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyExpiresAt),
|
"expiresAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyExpiresAt),
|
||||||
"createdAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyCreatedAt),
|
"createdAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyCreatedAt),
|
||||||
"updatedAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyUpdatedAt),
|
"updatedAt" => immutable_field_error(field, accepted, Code::ImmutableApiKeyUpdatedAt),
|
||||||
_ => unwrap_any(DeserrJsonError::<BadRequest>::error::<Infallible>(
|
_ => deserr::take_cf_content(DeserrJsonError::<BadRequest>::error::<Infallible>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::UnknownKey { key: field, accepted },
|
deserr::ErrorKind::UnknownKey { key: field, accepted },
|
||||||
location,
|
location,
|
||||||
@ -87,7 +86,7 @@ fn deny_immutable_fields_api_key(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, DeserializeFromValue)]
|
#[derive(Debug, Deserr)]
|
||||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields = deny_immutable_fields_api_key)]
|
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields = deny_immutable_fields_api_key)]
|
||||||
pub struct PatchApiKey {
|
pub struct PatchApiKey {
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidApiKeyDescription>)]
|
#[deserr(default, error = DeserrJsonError<InvalidApiKeyDescription>)]
|
||||||
@ -182,9 +181,7 @@ fn parse_expiration_date(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(
|
#[derive(Copy, Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Sequence, Deserr)]
|
||||||
Copy, Clone, Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Sequence, DeserializeFromValue,
|
|
||||||
)]
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
#[serde(rename = "*")]
|
#[serde(rename = "*")]
|
||||||
|
@ -3,9 +3,10 @@ use std::convert::Infallible;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::num::NonZeroUsize;
|
use std::num::NonZeroUsize;
|
||||||
|
use std::ops::ControlFlow;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use deserr::{DeserializeError, DeserializeFromValue, ErrorKind, MergeWithError, ValuePointerRef};
|
use deserr::{DeserializeError, Deserr, ErrorKind, MergeWithError, ValuePointerRef};
|
||||||
use fst::IntoStreamer;
|
use fst::IntoStreamer;
|
||||||
use milli::update::Setting;
|
use milli::update::Setting;
|
||||||
use milli::{Criterion, CriterionError, Index, DEFAULT_VALUES_PER_FACET};
|
use milli::{Criterion, CriterionError, Index, DEFAULT_VALUES_PER_FACET};
|
||||||
@ -13,7 +14,6 @@ use serde::{Deserialize, Serialize, Serializer};
|
|||||||
|
|
||||||
use crate::deserr::DeserrJsonError;
|
use crate::deserr::DeserrJsonError;
|
||||||
use crate::error::deserr_codes::*;
|
use crate::error::deserr_codes::*;
|
||||||
use crate::error::unwrap_any;
|
|
||||||
|
|
||||||
/// The maximimum number of results that the engine
|
/// The maximimum number of results that the engine
|
||||||
/// will be able to return in one search call.
|
/// will be able to return in one search call.
|
||||||
@ -41,7 +41,7 @@ pub struct Checked;
|
|||||||
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
#[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, Eq)]
|
||||||
pub struct Unchecked;
|
pub struct Unchecked;
|
||||||
|
|
||||||
impl<E> DeserializeFromValue<E> for Unchecked
|
impl<E> Deserr<E> for Unchecked
|
||||||
where
|
where
|
||||||
E: DeserializeError,
|
E: DeserializeError,
|
||||||
{
|
{
|
||||||
@ -59,13 +59,13 @@ fn validate_min_word_size_for_typo_setting<E: DeserializeError>(
|
|||||||
) -> Result<MinWordSizeTyposSetting, E> {
|
) -> Result<MinWordSizeTyposSetting, E> {
|
||||||
if let (Setting::Set(one), Setting::Set(two)) = (s.one_typo, s.two_typos) {
|
if let (Setting::Set(one), Setting::Set(two)) = (s.one_typo, s.two_typos) {
|
||||||
if one > two {
|
if one > two {
|
||||||
return Err(unwrap_any(E::error::<Infallible>(None, ErrorKind::Unexpected { msg: format!("`minWordSizeForTypos` setting is invalid. `oneTypo` and `twoTypos` fields should be between `0` and `255`, and `twoTypos` should be greater or equals to `oneTypo` but found `oneTypo: {one}` and twoTypos: {two}`.") }, location)));
|
return Err(deserr::take_cf_content(E::error::<Infallible>(None, ErrorKind::Unexpected { msg: format!("`minWordSizeForTypos` setting is invalid. `oneTypo` and `twoTypos` fields should be between `0` and `255`, and `twoTypos` should be greater or equals to `oneTypo` but found `oneTypo: {one}` and twoTypos: {two}`.") }, location)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(s)
|
Ok(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)]
|
||||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||||
#[deserr(deny_unknown_fields, rename_all = camelCase, validate = validate_min_word_size_for_typo_setting -> DeserrJsonError<InvalidSettingsTypoTolerance>)]
|
#[deserr(deny_unknown_fields, rename_all = camelCase, validate = validate_min_word_size_for_typo_setting -> DeserrJsonError<InvalidSettingsTypoTolerance>)]
|
||||||
pub struct MinWordSizeTyposSetting {
|
pub struct MinWordSizeTyposSetting {
|
||||||
@ -77,7 +77,7 @@ pub struct MinWordSizeTyposSetting {
|
|||||||
pub two_typos: Setting<u8>,
|
pub two_typos: Setting<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)]
|
||||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||||
#[deserr(deny_unknown_fields, rename_all = camelCase, where_predicate = __Deserr_E: deserr::MergeWithError<DeserrJsonError<InvalidSettingsTypoTolerance>>)]
|
#[deserr(deny_unknown_fields, rename_all = camelCase, where_predicate = __Deserr_E: deserr::MergeWithError<DeserrJsonError<InvalidSettingsTypoTolerance>>)]
|
||||||
pub struct TypoSettings {
|
pub struct TypoSettings {
|
||||||
@ -95,7 +95,7 @@ pub struct TypoSettings {
|
|||||||
pub disable_on_attributes: Setting<BTreeSet<String>>,
|
pub disable_on_attributes: Setting<BTreeSet<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)]
|
||||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||||
#[deserr(rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct FacetingSettings {
|
pub struct FacetingSettings {
|
||||||
@ -104,7 +104,7 @@ pub struct FacetingSettings {
|
|||||||
pub max_values_per_facet: Setting<usize>,
|
pub max_values_per_facet: Setting<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)]
|
||||||
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
#[serde(deny_unknown_fields, rename_all = "camelCase")]
|
||||||
#[deserr(rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct PaginationSettings {
|
pub struct PaginationSettings {
|
||||||
@ -118,7 +118,7 @@ impl MergeWithError<milli::CriterionError> for DeserrJsonError<InvalidSettingsRa
|
|||||||
_self_: Option<Self>,
|
_self_: Option<Self>,
|
||||||
other: milli::CriterionError,
|
other: milli::CriterionError,
|
||||||
merge_location: ValuePointerRef,
|
merge_location: ValuePointerRef,
|
||||||
) -> Result<Self, Self> {
|
) -> ControlFlow<Self, Self> {
|
||||||
Self::error::<Infallible>(
|
Self::error::<Infallible>(
|
||||||
None,
|
None,
|
||||||
ErrorKind::Unexpected { msg: other.to_string() },
|
ErrorKind::Unexpected { msg: other.to_string() },
|
||||||
@ -130,7 +130,7 @@ impl MergeWithError<milli::CriterionError> for DeserrJsonError<InvalidSettingsRa
|
|||||||
/// Holds all the settings for an index. `T` can either be `Checked` if they represents settings
|
/// Holds all the settings for an index. `T` can either be `Checked` if they represents settings
|
||||||
/// whose validity is guaranteed, or `Unchecked` if they need to be validated. In the later case, a
|
/// whose validity is guaranteed, or `Unchecked` if they need to be validated. In the later case, a
|
||||||
/// call to `check` will return a `Settings<Checked>` from a `Settings<Unchecked>`.
|
/// call to `check` will return a `Settings<Checked>` from a `Settings<Unchecked>`.
|
||||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, DeserializeFromValue)]
|
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)]
|
||||||
#[serde(
|
#[serde(
|
||||||
deny_unknown_fields,
|
deny_unknown_fields,
|
||||||
rename_all = "camelCase",
|
rename_all = "camelCase",
|
||||||
@ -509,8 +509,8 @@ pub fn settings(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, DeserializeFromValue)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserr)]
|
||||||
#[deserr(from(&String) = FromStr::from_str -> CriterionError)]
|
#[deserr(try_from(&String) = FromStr::from_str -> CriterionError)]
|
||||||
pub enum RankingRuleView {
|
pub enum RankingRuleView {
|
||||||
/// Sorted by decreasing number of matched query terms.
|
/// Sorted by decreasing number of matched query terms.
|
||||||
/// Query words at the front of an attribute is considered better than if it was at the back.
|
/// Query words at the front of an attribute is considered better than if it was at the back.
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
use std::ops::ControlFlow;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use deserr::{DeserializeError, DeserializeFromValue, MergeWithError, ValueKind};
|
use deserr::{DeserializeError, Deserr, MergeWithError, ValueKind};
|
||||||
use serde::de::Visitor;
|
use serde::de::Visitor;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
|
|
||||||
use crate::deserr::query_params::FromQueryParameter;
|
use crate::deserr::query_params::FromQueryParameter;
|
||||||
use crate::error::unwrap_any;
|
|
||||||
|
|
||||||
/// A type that tries to match either a star (*) or
|
/// A type that tries to match either a star (*) or
|
||||||
/// any other thing that implements `FromStr`.
|
/// any other thing that implements `FromStr`.
|
||||||
@ -111,7 +111,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> DeserializeFromValue<E> for StarOr<T>
|
impl<T, E> Deserr<E> for StarOr<T>
|
||||||
where
|
where
|
||||||
T: FromStr,
|
T: FromStr,
|
||||||
E: DeserializeError + MergeWithError<T::Err>,
|
E: DeserializeError + MergeWithError<T::Err>,
|
||||||
@ -127,11 +127,11 @@ where
|
|||||||
} else {
|
} else {
|
||||||
match T::from_str(&v) {
|
match T::from_str(&v) {
|
||||||
Ok(parsed) => Ok(StarOr::Other(parsed)),
|
Ok(parsed) => Ok(StarOr::Other(parsed)),
|
||||||
Err(e) => Err(unwrap_any(E::merge(None, e, location))),
|
Err(e) => Err(deserr::take_cf_content(E::merge(None, e, location))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(unwrap_any(E::error::<V>(
|
_ => Err(deserr::take_cf_content(E::error::<V>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::IncorrectValueKind {
|
deserr::ErrorKind::IncorrectValueKind {
|
||||||
actual: value,
|
actual: value,
|
||||||
@ -191,7 +191,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> DeserializeFromValue<E> for OptionStarOr<T>
|
impl<T, E> Deserr<E> for OptionStarOr<T>
|
||||||
where
|
where
|
||||||
E: DeserializeError + MergeWithError<T::Err>,
|
E: DeserializeError + MergeWithError<T::Err>,
|
||||||
T: FromQueryParameter,
|
T: FromQueryParameter,
|
||||||
@ -205,10 +205,10 @@ where
|
|||||||
"*" => Ok(OptionStarOr::Star),
|
"*" => Ok(OptionStarOr::Star),
|
||||||
s => match T::from_query_param(s) {
|
s => match T::from_query_param(s) {
|
||||||
Ok(x) => Ok(OptionStarOr::Other(x)),
|
Ok(x) => Ok(OptionStarOr::Other(x)),
|
||||||
Err(e) => Err(unwrap_any(E::merge(None, e, location))),
|
Err(e) => Err(deserr::take_cf_content(E::merge(None, e, location))),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_ => Err(unwrap_any(E::error::<V>(
|
_ => Err(deserr::take_cf_content(E::error::<V>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::IncorrectValueKind {
|
deserr::ErrorKind::IncorrectValueKind {
|
||||||
actual: value,
|
actual: value,
|
||||||
@ -271,7 +271,7 @@ impl<T> OptionStarOrList<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> DeserializeFromValue<E> for OptionStarOrList<T>
|
impl<T, E> Deserr<E> for OptionStarOrList<T>
|
||||||
where
|
where
|
||||||
E: DeserializeError + MergeWithError<T::Err>,
|
E: DeserializeError + MergeWithError<T::Err>,
|
||||||
T: FromQueryParameter,
|
T: FromQueryParameter,
|
||||||
@ -299,7 +299,10 @@ where
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
let location =
|
let location =
|
||||||
if len_cs > 1 { location.push_index(i) } else { location };
|
if len_cs > 1 { location.push_index(i) } else { location };
|
||||||
error = Some(E::merge(error, e, location)?);
|
error = match E::merge(error, e, location) {
|
||||||
|
ControlFlow::Continue(e) => Some(e),
|
||||||
|
ControlFlow::Break(e) => return Err(e),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -314,7 +317,7 @@ where
|
|||||||
Ok(OptionStarOrList::List(els))
|
Ok(OptionStarOrList::List(els))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(unwrap_any(E::error::<V>(
|
_ => Err(deserr::take_cf_content(E::error::<V>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::IncorrectValueKind {
|
deserr::ErrorKind::IncorrectValueKind {
|
||||||
actual: value,
|
actual: value,
|
||||||
|
@ -19,7 +19,7 @@ byte-unit = { version = "4.0.14", default-features = false, features = ["std", "
|
|||||||
bytes = "1.2.1"
|
bytes = "1.2.1"
|
||||||
clap = { version = "4.0.9", features = ["derive", "env"] }
|
clap = { version = "4.0.9", features = ["derive", "env"] }
|
||||||
crossbeam-channel = "0.5.6"
|
crossbeam-channel = "0.5.6"
|
||||||
deserr = "0.3.0"
|
deserr = "0.4.1"
|
||||||
dump = { path = "../dump" }
|
dump = { path = "../dump" }
|
||||||
either = "1.8.0"
|
either = "1.8.0"
|
||||||
env_logger = "0.9.1"
|
env_logger = "0.9.1"
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
use std::fmt::Debug;
|
|
||||||
use std::future::Future;
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::pin::Pin;
|
|
||||||
use std::task::{Context, Poll};
|
|
||||||
|
|
||||||
use actix_web::dev::Payload;
|
|
||||||
use actix_web::web::Json;
|
|
||||||
use actix_web::{FromRequest, HttpRequest};
|
|
||||||
use deserr::{DeserializeError, DeserializeFromValue};
|
|
||||||
use futures::ready;
|
|
||||||
use meilisearch_types::error::{ErrorCode, ResponseError};
|
|
||||||
|
|
||||||
/// Extractor for typed data from Json request payloads
|
|
||||||
/// deserialised by deserr.
|
|
||||||
///
|
|
||||||
/// # Extractor
|
|
||||||
/// To extract typed data from a request body, the inner type `T` must implement the
|
|
||||||
/// [`deserr::DeserializeFromError<E>`] trait. The inner type `E` must implement the
|
|
||||||
/// [`ErrorCode`](meilisearch_error::ErrorCode) trait.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ValidatedJson<T, E>(pub T, PhantomData<*const E>);
|
|
||||||
|
|
||||||
impl<T, E> ValidatedJson<T, E> {
|
|
||||||
pub fn new(data: T) -> Self {
|
|
||||||
ValidatedJson(data, PhantomData)
|
|
||||||
}
|
|
||||||
pub fn into_inner(self) -> T {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E> FromRequest for ValidatedJson<T, E>
|
|
||||||
where
|
|
||||||
E: DeserializeError + ErrorCode + std::error::Error + 'static,
|
|
||||||
T: DeserializeFromValue<E>,
|
|
||||||
{
|
|
||||||
type Error = actix_web::Error;
|
|
||||||
type Future = ValidatedJsonExtractFut<T, E>;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
|
||||||
ValidatedJsonExtractFut {
|
|
||||||
fut: Json::<serde_json::Value>::from_request(req, payload),
|
|
||||||
_phantom: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct ValidatedJsonExtractFut<T, E> {
|
|
||||||
fut: <Json<serde_json::Value> as FromRequest>::Future,
|
|
||||||
_phantom: PhantomData<*const (T, E)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E> Future for ValidatedJsonExtractFut<T, E>
|
|
||||||
where
|
|
||||||
T: DeserializeFromValue<E>,
|
|
||||||
E: DeserializeError + ErrorCode + std::error::Error + 'static,
|
|
||||||
{
|
|
||||||
type Output = Result<ValidatedJson<T, E>, actix_web::Error>;
|
|
||||||
|
|
||||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
|
||||||
let ValidatedJsonExtractFut { fut, .. } = self.get_mut();
|
|
||||||
let fut = Pin::new(fut);
|
|
||||||
|
|
||||||
let res = ready!(fut.poll(cx));
|
|
||||||
|
|
||||||
let res = match res {
|
|
||||||
Err(err) => Err(err),
|
|
||||||
Ok(data) => match deserr::deserialize::<_, _, E>(data.into_inner()) {
|
|
||||||
Ok(data) => Ok(ValidatedJson::new(data)),
|
|
||||||
Err(e) => Err(ResponseError::from(e).into()),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
Poll::Ready(res)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,4 @@
|
|||||||
pub mod payload;
|
pub mod payload;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod authentication;
|
pub mod authentication;
|
||||||
pub mod json;
|
|
||||||
pub mod query_parameters;
|
|
||||||
pub mod sequential_extractor;
|
pub mod sequential_extractor;
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
//! A module to parse query parameter with deserr
|
|
||||||
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
use std::{fmt, ops};
|
|
||||||
|
|
||||||
use actix_http::Payload;
|
|
||||||
use actix_utils::future::{err, ok, Ready};
|
|
||||||
use actix_web::{FromRequest, HttpRequest};
|
|
||||||
use deserr::{DeserializeError, DeserializeFromValue};
|
|
||||||
use meilisearch_types::error::{Code, ErrorCode, ResponseError};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
||||||
pub struct QueryParameter<T, E>(pub T, PhantomData<*const E>);
|
|
||||||
|
|
||||||
impl<T, E> QueryParameter<T, E> {
|
|
||||||
/// Unwrap into inner `T` value.
|
|
||||||
pub fn into_inner(self) -> T {
|
|
||||||
self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E> QueryParameter<T, E>
|
|
||||||
where
|
|
||||||
T: DeserializeFromValue<E>,
|
|
||||||
E: DeserializeError + ErrorCode + std::error::Error + 'static,
|
|
||||||
{
|
|
||||||
pub fn from_query(query_str: &str) -> Result<Self, actix_web::Error> {
|
|
||||||
let value = serde_urlencoded::from_str::<serde_json::Value>(query_str)
|
|
||||||
.map_err(|e| ResponseError::from_msg(e.to_string(), Code::BadRequest))?;
|
|
||||||
|
|
||||||
match deserr::deserialize::<_, _, E>(value) {
|
|
||||||
Ok(data) => Ok(QueryParameter(data, PhantomData)),
|
|
||||||
Err(e) => Err(ResponseError::from(e).into()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E> ops::Deref for QueryParameter<T, E> {
|
|
||||||
type Target = T;
|
|
||||||
|
|
||||||
fn deref(&self) -> &T {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E> ops::DerefMut for QueryParameter<T, E> {
|
|
||||||
fn deref_mut(&mut self) -> &mut T {
|
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T: fmt::Display, E> fmt::Display for QueryParameter<T, E> {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
self.0.fmt(f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, E> FromRequest for QueryParameter<T, E>
|
|
||||||
where
|
|
||||||
T: DeserializeFromValue<E>,
|
|
||||||
E: DeserializeError + ErrorCode + std::error::Error + 'static,
|
|
||||||
{
|
|
||||||
type Error = actix_web::Error;
|
|
||||||
type Future = Ready<Result<Self, actix_web::Error>>;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
|
||||||
QueryParameter::from_query(req.query_string()).map(ok).unwrap_or_else(err)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,8 @@
|
|||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use deserr::DeserializeFromValue;
|
use deserr::actix_web::{AwebJson, AwebQueryParameter};
|
||||||
|
use deserr::Deserr;
|
||||||
use meilisearch_auth::error::AuthControllerError;
|
use meilisearch_auth::error::AuthControllerError;
|
||||||
use meilisearch_auth::AuthController;
|
use meilisearch_auth::AuthController;
|
||||||
use meilisearch_types::deserr::query_params::Param;
|
use meilisearch_types::deserr::query_params::Param;
|
||||||
@ -16,8 +17,6 @@ use uuid::Uuid;
|
|||||||
use super::PAGINATION_DEFAULT_LIMIT;
|
use super::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::json::ValidatedJson;
|
|
||||||
use crate::extractors::query_parameters::QueryParameter;
|
|
||||||
use crate::extractors::sequential_extractor::SeqHandler;
|
use crate::extractors::sequential_extractor::SeqHandler;
|
||||||
use crate::routes::Pagination;
|
use crate::routes::Pagination;
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
|
|
||||||
pub async fn create_api_key(
|
pub async fn create_api_key(
|
||||||
auth_controller: GuardedData<ActionPolicy<{ actions::KEYS_CREATE }>, AuthController>,
|
auth_controller: GuardedData<ActionPolicy<{ actions::KEYS_CREATE }>, AuthController>,
|
||||||
body: ValidatedJson<CreateApiKey, DeserrJsonError>,
|
body: AwebJson<CreateApiKey, DeserrJsonError>,
|
||||||
_req: HttpRequest,
|
_req: HttpRequest,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let v = body.into_inner();
|
let v = body.into_inner();
|
||||||
@ -51,7 +50,7 @@ pub async fn create_api_key(
|
|||||||
Ok(HttpResponse::Created().json(res))
|
Ok(HttpResponse::Created().json(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(DeserializeFromValue, Debug, Clone, Copy)]
|
#[derive(Deserr, Debug, Clone, Copy)]
|
||||||
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct ListApiKeys {
|
pub struct ListApiKeys {
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidApiKeyOffset>)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidApiKeyOffset>)]
|
||||||
@ -68,7 +67,7 @@ impl ListApiKeys {
|
|||||||
|
|
||||||
pub async fn list_api_keys(
|
pub async fn list_api_keys(
|
||||||
auth_controller: GuardedData<ActionPolicy<{ actions::KEYS_GET }>, AuthController>,
|
auth_controller: GuardedData<ActionPolicy<{ actions::KEYS_GET }>, AuthController>,
|
||||||
list_api_keys: QueryParameter<ListApiKeys, DeserrQueryParamError>,
|
list_api_keys: AwebQueryParameter<ListApiKeys, DeserrQueryParamError>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let paginate = list_api_keys.into_inner().as_pagination();
|
let paginate = list_api_keys.into_inner().as_pagination();
|
||||||
let page_view = tokio::task::spawn_blocking(move || -> Result<_, AuthControllerError> {
|
let page_view = tokio::task::spawn_blocking(move || -> Result<_, AuthControllerError> {
|
||||||
@ -105,7 +104,7 @@ pub async fn get_api_key(
|
|||||||
|
|
||||||
pub async fn patch_api_key(
|
pub async fn patch_api_key(
|
||||||
auth_controller: GuardedData<ActionPolicy<{ actions::KEYS_UPDATE }>, AuthController>,
|
auth_controller: GuardedData<ActionPolicy<{ actions::KEYS_UPDATE }>, AuthController>,
|
||||||
body: ValidatedJson<PatchApiKey, DeserrJsonError>,
|
body: AwebJson<PatchApiKey, DeserrJsonError>,
|
||||||
path: web::Path<AuthParam>,
|
path: web::Path<AuthParam>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let key = path.into_inner().key;
|
let key = path.into_inner().key;
|
||||||
|
@ -4,7 +4,8 @@ use actix_web::http::header::CONTENT_TYPE;
|
|||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{web, HttpMessage, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpMessage, HttpRequest, HttpResponse};
|
||||||
use bstr::ByteSlice;
|
use bstr::ByteSlice;
|
||||||
use deserr::DeserializeFromValue;
|
use deserr::actix_web::AwebQueryParameter;
|
||||||
|
use deserr::Deserr;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use index_scheduler::IndexScheduler;
|
use index_scheduler::IndexScheduler;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
@ -33,7 +34,6 @@ use crate::error::PayloadError::ReceivePayload;
|
|||||||
use crate::extractors::authentication::policies::*;
|
use crate::extractors::authentication::policies::*;
|
||||||
use crate::extractors::authentication::GuardedData;
|
use crate::extractors::authentication::GuardedData;
|
||||||
use crate::extractors::payload::Payload;
|
use crate::extractors::payload::Payload;
|
||||||
use crate::extractors::query_parameters::QueryParameter;
|
|
||||||
use crate::extractors::sequential_extractor::SeqHandler;
|
use crate::extractors::sequential_extractor::SeqHandler;
|
||||||
use crate::routes::{PaginationView, SummarizedTaskView, PAGINATION_DEFAULT_LIMIT};
|
use crate::routes::{PaginationView, SummarizedTaskView, PAGINATION_DEFAULT_LIMIT};
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, DeserializeFromValue)]
|
#[derive(Debug, Deserr)]
|
||||||
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct GetDocument {
|
pub struct GetDocument {
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidDocumentFields>)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidDocumentFields>)]
|
||||||
@ -90,7 +90,7 @@ pub struct GetDocument {
|
|||||||
pub async fn get_document(
|
pub async fn get_document(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::DOCUMENTS_GET }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::DOCUMENTS_GET }>, Data<IndexScheduler>>,
|
||||||
document_param: web::Path<DocumentParam>,
|
document_param: web::Path<DocumentParam>,
|
||||||
params: QueryParameter<GetDocument, DeserrQueryParamError>,
|
params: AwebQueryParameter<GetDocument, DeserrQueryParamError>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let DocumentParam { index_uid, document_id } = document_param.into_inner();
|
let DocumentParam { index_uid, document_id } = document_param.into_inner();
|
||||||
let index_uid = IndexUid::try_from(index_uid)?;
|
let index_uid = IndexUid::try_from(index_uid)?;
|
||||||
@ -125,7 +125,7 @@ pub async fn delete_document(
|
|||||||
Ok(HttpResponse::Accepted().json(task))
|
Ok(HttpResponse::Accepted().json(task))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, DeserializeFromValue)]
|
#[derive(Debug, Deserr)]
|
||||||
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct BrowseQuery {
|
pub struct BrowseQuery {
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidDocumentOffset>)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidDocumentOffset>)]
|
||||||
@ -139,7 +139,7 @@ pub struct BrowseQuery {
|
|||||||
pub async fn get_all_documents(
|
pub async fn get_all_documents(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::DOCUMENTS_GET }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::DOCUMENTS_GET }>, Data<IndexScheduler>>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
params: QueryParameter<BrowseQuery, DeserrQueryParamError>,
|
params: AwebQueryParameter<BrowseQuery, DeserrQueryParamError>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let index_uid = IndexUid::try_from(index_uid.into_inner())?;
|
let index_uid = IndexUid::try_from(index_uid.into_inner())?;
|
||||||
debug!("called with params: {:?}", params);
|
debug!("called with params: {:?}", params);
|
||||||
@ -155,7 +155,7 @@ pub async fn get_all_documents(
|
|||||||
Ok(HttpResponse::Ok().json(ret))
|
Ok(HttpResponse::Ok().json(ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, DeserializeFromValue)]
|
#[derive(Deserialize, Debug, Deserr)]
|
||||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct UpdateDocumentsQuery {
|
pub struct UpdateDocumentsQuery {
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidIndexPrimaryKey>)]
|
#[deserr(default, error = DeserrJsonError<InvalidIndexPrimaryKey>)]
|
||||||
@ -165,7 +165,7 @@ pub struct UpdateDocumentsQuery {
|
|||||||
pub async fn add_documents(
|
pub async fn add_documents(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::DOCUMENTS_ADD }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::DOCUMENTS_ADD }>, Data<IndexScheduler>>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
params: QueryParameter<UpdateDocumentsQuery, DeserrJsonError>,
|
params: AwebQueryParameter<UpdateDocumentsQuery, DeserrJsonError>,
|
||||||
body: Payload,
|
body: Payload,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
@ -195,7 +195,7 @@ pub async fn add_documents(
|
|||||||
pub async fn update_documents(
|
pub async fn update_documents(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::DOCUMENTS_ADD }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::DOCUMENTS_ADD }>, Data<IndexScheduler>>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
params: QueryParameter<UpdateDocumentsQuery, DeserrJsonError>,
|
params: AwebQueryParameter<UpdateDocumentsQuery, DeserrJsonError>,
|
||||||
body: Payload,
|
body: Payload,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
|
@ -2,14 +2,14 @@ use std::convert::Infallible;
|
|||||||
|
|
||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use deserr::{DeserializeError, DeserializeFromValue, ValuePointerRef};
|
use deserr::actix_web::{AwebJson, AwebQueryParameter};
|
||||||
|
use deserr::{DeserializeError, Deserr, ValuePointerRef};
|
||||||
use index_scheduler::IndexScheduler;
|
use index_scheduler::IndexScheduler;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use meilisearch_types::deserr::error_messages::immutable_field_error;
|
|
||||||
use meilisearch_types::deserr::query_params::Param;
|
use meilisearch_types::deserr::query_params::Param;
|
||||||
use meilisearch_types::deserr::{DeserrJsonError, DeserrQueryParamError};
|
use meilisearch_types::deserr::{immutable_field_error, DeserrJsonError, DeserrQueryParamError};
|
||||||
use meilisearch_types::error::deserr_codes::*;
|
use meilisearch_types::error::deserr_codes::*;
|
||||||
use meilisearch_types::error::{unwrap_any, Code, ResponseError};
|
use meilisearch_types::error::{Code, ResponseError};
|
||||||
use meilisearch_types::index_uid::IndexUid;
|
use meilisearch_types::index_uid::IndexUid;
|
||||||
use meilisearch_types::milli::{self, FieldDistribution, Index};
|
use meilisearch_types::milli::{self, FieldDistribution, Index};
|
||||||
use meilisearch_types::tasks::KindWithContent;
|
use meilisearch_types::tasks::KindWithContent;
|
||||||
@ -21,8 +21,6 @@ use super::{Pagination, SummarizedTaskView, PAGINATION_DEFAULT_LIMIT};
|
|||||||
use crate::analytics::Analytics;
|
use crate::analytics::Analytics;
|
||||||
use crate::extractors::authentication::policies::*;
|
use crate::extractors::authentication::policies::*;
|
||||||
use crate::extractors::authentication::{AuthenticationError, GuardedData};
|
use crate::extractors::authentication::{AuthenticationError, GuardedData};
|
||||||
use crate::extractors::json::ValidatedJson;
|
|
||||||
use crate::extractors::query_parameters::QueryParameter;
|
|
||||||
use crate::extractors::sequential_extractor::SeqHandler;
|
use crate::extractors::sequential_extractor::SeqHandler;
|
||||||
|
|
||||||
pub mod documents;
|
pub mod documents;
|
||||||
@ -73,7 +71,7 @@ impl IndexView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(DeserializeFromValue, Debug, Clone, Copy)]
|
#[derive(Deserr, Debug, Clone, Copy)]
|
||||||
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct ListIndexes {
|
pub struct ListIndexes {
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidIndexOffset>)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidIndexOffset>)]
|
||||||
@ -89,7 +87,7 @@ impl ListIndexes {
|
|||||||
|
|
||||||
pub async fn list_indexes(
|
pub async fn list_indexes(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::INDEXES_GET }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::INDEXES_GET }>, Data<IndexScheduler>>,
|
||||||
paginate: QueryParameter<ListIndexes, DeserrQueryParamError>,
|
paginate: AwebQueryParameter<ListIndexes, DeserrQueryParamError>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
let search_rules = &index_scheduler.filters().search_rules;
|
let search_rules = &index_scheduler.filters().search_rules;
|
||||||
let indexes: Vec<_> = index_scheduler.indexes()?;
|
let indexes: Vec<_> = index_scheduler.indexes()?;
|
||||||
@ -105,7 +103,7 @@ pub async fn list_indexes(
|
|||||||
Ok(HttpResponse::Ok().json(ret))
|
Ok(HttpResponse::Ok().json(ret))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(DeserializeFromValue, Debug)]
|
#[derive(Deserr, Debug)]
|
||||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct IndexCreateRequest {
|
pub struct IndexCreateRequest {
|
||||||
#[deserr(error = DeserrJsonError<InvalidIndexUid>, missing_field_error = DeserrJsonError::missing_index_uid)]
|
#[deserr(error = DeserrJsonError<InvalidIndexUid>, missing_field_error = DeserrJsonError::missing_index_uid)]
|
||||||
@ -116,7 +114,7 @@ pub struct IndexCreateRequest {
|
|||||||
|
|
||||||
pub async fn create_index(
|
pub async fn create_index(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::INDEXES_CREATE }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::INDEXES_CREATE }>, Data<IndexScheduler>>,
|
||||||
body: ValidatedJson<IndexCreateRequest, DeserrJsonError>,
|
body: AwebJson<IndexCreateRequest, DeserrJsonError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
@ -149,7 +147,7 @@ fn deny_immutable_fields_index(
|
|||||||
"uid" => immutable_field_error(field, accepted, Code::ImmutableIndexUid),
|
"uid" => immutable_field_error(field, accepted, Code::ImmutableIndexUid),
|
||||||
"createdAt" => immutable_field_error(field, accepted, Code::ImmutableIndexCreatedAt),
|
"createdAt" => immutable_field_error(field, accepted, Code::ImmutableIndexCreatedAt),
|
||||||
"updatedAt" => immutable_field_error(field, accepted, Code::ImmutableIndexUpdatedAt),
|
"updatedAt" => immutable_field_error(field, accepted, Code::ImmutableIndexUpdatedAt),
|
||||||
_ => unwrap_any(DeserrJsonError::<BadRequest>::error::<Infallible>(
|
_ => deserr::take_cf_content(DeserrJsonError::<BadRequest>::error::<Infallible>(
|
||||||
None,
|
None,
|
||||||
deserr::ErrorKind::UnknownKey { key: field, accepted },
|
deserr::ErrorKind::UnknownKey { key: field, accepted },
|
||||||
location,
|
location,
|
||||||
@ -157,7 +155,7 @@ fn deny_immutable_fields_index(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(DeserializeFromValue, Debug)]
|
#[derive(Deserr, Debug)]
|
||||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields = deny_immutable_fields_index)]
|
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields = deny_immutable_fields_index)]
|
||||||
pub struct UpdateIndexRequest {
|
pub struct UpdateIndexRequest {
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidIndexPrimaryKey>)]
|
#[deserr(default, error = DeserrJsonError<InvalidIndexPrimaryKey>)]
|
||||||
@ -181,7 +179,7 @@ pub async fn get_index(
|
|||||||
pub async fn update_index(
|
pub async fn update_index(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::INDEXES_UPDATE }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::INDEXES_UPDATE }>, Data<IndexScheduler>>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
body: ValidatedJson<UpdateIndexRequest, DeserrJsonError>,
|
body: AwebJson<UpdateIndexRequest, DeserrJsonError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
|
use deserr::actix_web::{AwebJson, AwebQueryParameter};
|
||||||
use index_scheduler::IndexScheduler;
|
use index_scheduler::IndexScheduler;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use meilisearch_auth::IndexSearchRules;
|
use meilisearch_auth::IndexSearchRules;
|
||||||
@ -14,8 +15,6 @@ use serde_json::Value;
|
|||||||
use crate::analytics::{Analytics, SearchAggregator};
|
use crate::analytics::{Analytics, SearchAggregator};
|
||||||
use crate::extractors::authentication::policies::*;
|
use crate::extractors::authentication::policies::*;
|
||||||
use crate::extractors::authentication::GuardedData;
|
use crate::extractors::authentication::GuardedData;
|
||||||
use crate::extractors::json::ValidatedJson;
|
|
||||||
use crate::extractors::query_parameters::QueryParameter;
|
|
||||||
use crate::extractors::sequential_extractor::SeqHandler;
|
use crate::extractors::sequential_extractor::SeqHandler;
|
||||||
use crate::search::{
|
use crate::search::{
|
||||||
perform_search, MatchingStrategy, SearchQuery, DEFAULT_CROP_LENGTH, DEFAULT_CROP_MARKER,
|
perform_search, MatchingStrategy, SearchQuery, DEFAULT_CROP_LENGTH, DEFAULT_CROP_MARKER,
|
||||||
@ -31,7 +30,7 @@ pub fn configure(cfg: &mut web::ServiceConfig) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, deserr::DeserializeFromValue)]
|
#[derive(Debug, deserr::Deserr)]
|
||||||
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct SearchQueryGet {
|
pub struct SearchQueryGet {
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidSearchQ>)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidSearchQ>)]
|
||||||
@ -150,7 +149,7 @@ fn fix_sort_query_parameters(sort_query: &str) -> Vec<String> {
|
|||||||
pub async fn search_with_url_query(
|
pub async fn search_with_url_query(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::SEARCH }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::SEARCH }>, Data<IndexScheduler>>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
params: QueryParameter<SearchQueryGet, DeserrQueryParamError>,
|
params: AwebQueryParameter<SearchQueryGet, DeserrQueryParamError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
@ -184,7 +183,7 @@ pub async fn search_with_url_query(
|
|||||||
pub async fn search_with_post(
|
pub async fn search_with_post(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::SEARCH }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::SEARCH }>, Data<IndexScheduler>>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
params: ValidatedJson<SearchQuery, DeserrJsonError>,
|
params: AwebJson<SearchQuery, DeserrJsonError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
|
use deserr::actix_web::AwebJson;
|
||||||
use index_scheduler::IndexScheduler;
|
use index_scheduler::IndexScheduler;
|
||||||
use log::debug;
|
use log::debug;
|
||||||
use meilisearch_types::deserr::DeserrJsonError;
|
use meilisearch_types::deserr::DeserrJsonError;
|
||||||
@ -12,7 +13,6 @@ use serde_json::json;
|
|||||||
use crate::analytics::Analytics;
|
use crate::analytics::Analytics;
|
||||||
use crate::extractors::authentication::policies::*;
|
use crate::extractors::authentication::policies::*;
|
||||||
use crate::extractors::authentication::GuardedData;
|
use crate::extractors::authentication::GuardedData;
|
||||||
use crate::extractors::json::ValidatedJson;
|
|
||||||
use crate::routes::SummarizedTaskView;
|
use crate::routes::SummarizedTaskView;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
@ -68,7 +68,7 @@ macro_rules! make_setting_route {
|
|||||||
Data<IndexScheduler>,
|
Data<IndexScheduler>,
|
||||||
>,
|
>,
|
||||||
index_uid: actix_web::web::Path<String>,
|
index_uid: actix_web::web::Path<String>,
|
||||||
body: $crate::routes::indexes::ValidatedJson<Option<$type>, $err_ty>,
|
body: deserr::actix_web::AwebJson<Option<$type>, $err_ty>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
$analytics_var: web::Data<dyn Analytics>,
|
$analytics_var: web::Data<dyn Analytics>,
|
||||||
) -> std::result::Result<HttpResponse, ResponseError> {
|
) -> std::result::Result<HttpResponse, ResponseError> {
|
||||||
@ -468,7 +468,7 @@ generate_configure!(
|
|||||||
pub async fn update_all(
|
pub async fn update_all(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::SETTINGS_UPDATE }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::SETTINGS_UPDATE }>, Data<IndexScheduler>>,
|
||||||
index_uid: web::Path<String>,
|
index_uid: web::Path<String>,
|
||||||
body: ValidatedJson<Settings<Unchecked>, DeserrJsonError>,
|
body: AwebJson<Settings<Unchecked>, DeserrJsonError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use deserr::DeserializeFromValue;
|
use deserr::actix_web::AwebJson;
|
||||||
|
use deserr::Deserr;
|
||||||
use index_scheduler::IndexScheduler;
|
use index_scheduler::IndexScheduler;
|
||||||
use meilisearch_types::deserr::DeserrJsonError;
|
use meilisearch_types::deserr::DeserrJsonError;
|
||||||
use meilisearch_types::error::deserr_codes::InvalidSwapIndexes;
|
use meilisearch_types::error::deserr_codes::InvalidSwapIndexes;
|
||||||
@ -14,14 +15,13 @@ use crate::analytics::Analytics;
|
|||||||
use crate::error::MeilisearchHttpError;
|
use crate::error::MeilisearchHttpError;
|
||||||
use crate::extractors::authentication::policies::*;
|
use crate::extractors::authentication::policies::*;
|
||||||
use crate::extractors::authentication::{AuthenticationError, GuardedData};
|
use crate::extractors::authentication::{AuthenticationError, GuardedData};
|
||||||
use crate::extractors::json::ValidatedJson;
|
|
||||||
use crate::extractors::sequential_extractor::SeqHandler;
|
use crate::extractors::sequential_extractor::SeqHandler;
|
||||||
|
|
||||||
pub fn configure(cfg: &mut web::ServiceConfig) {
|
pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||||
cfg.service(web::resource("").route(web::post().to(SeqHandler(swap_indexes))));
|
cfg.service(web::resource("").route(web::post().to(SeqHandler(swap_indexes))));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(DeserializeFromValue, Debug, Clone, PartialEq, Eq)]
|
#[derive(Deserr, Debug, Clone, PartialEq, Eq)]
|
||||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct SwapIndexesPayload {
|
pub struct SwapIndexesPayload {
|
||||||
#[deserr(error = DeserrJsonError<InvalidSwapIndexes>, missing_field_error = DeserrJsonError::missing_swap_indexes)]
|
#[deserr(error = DeserrJsonError<InvalidSwapIndexes>, missing_field_error = DeserrJsonError::missing_swap_indexes)]
|
||||||
@ -30,7 +30,7 @@ pub struct SwapIndexesPayload {
|
|||||||
|
|
||||||
pub async fn swap_indexes(
|
pub async fn swap_indexes(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::INDEXES_SWAP }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::INDEXES_SWAP }>, Data<IndexScheduler>>,
|
||||||
params: ValidatedJson<Vec<SwapIndexesPayload>, DeserrJsonError>,
|
params: AwebJson<Vec<SwapIndexesPayload>, DeserrJsonError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use actix_web::web::Data;
|
use actix_web::web::Data;
|
||||||
use actix_web::{web, HttpRequest, HttpResponse};
|
use actix_web::{web, HttpRequest, HttpResponse};
|
||||||
use deserr::DeserializeFromValue;
|
use deserr::actix_web::AwebQueryParameter;
|
||||||
|
use deserr::Deserr;
|
||||||
use index_scheduler::{IndexScheduler, Query, TaskId};
|
use index_scheduler::{IndexScheduler, Query, TaskId};
|
||||||
use meilisearch_types::deserr::query_params::Param;
|
use meilisearch_types::deserr::query_params::Param;
|
||||||
use meilisearch_types::deserr::DeserrQueryParamError;
|
use meilisearch_types::deserr::DeserrQueryParamError;
|
||||||
@ -23,7 +24,6 @@ use super::SummarizedTaskView;
|
|||||||
use crate::analytics::Analytics;
|
use crate::analytics::Analytics;
|
||||||
use crate::extractors::authentication::policies::*;
|
use crate::extractors::authentication::policies::*;
|
||||||
use crate::extractors::authentication::GuardedData;
|
use crate::extractors::authentication::GuardedData;
|
||||||
use crate::extractors::query_parameters::QueryParameter;
|
|
||||||
use crate::extractors::sequential_extractor::SeqHandler;
|
use crate::extractors::sequential_extractor::SeqHandler;
|
||||||
|
|
||||||
const DEFAULT_LIMIT: u32 = 20;
|
const DEFAULT_LIMIT: u32 = 20;
|
||||||
@ -162,7 +162,7 @@ impl From<Details> for DetailsView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, DeserializeFromValue)]
|
#[derive(Debug, Deserr)]
|
||||||
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct TasksFilterQuery {
|
pub struct TasksFilterQuery {
|
||||||
#[deserr(default = Param(DEFAULT_LIMIT), error = DeserrQueryParamError<InvalidTaskLimit>)]
|
#[deserr(default = Param(DEFAULT_LIMIT), error = DeserrQueryParamError<InvalidTaskLimit>)]
|
||||||
@ -181,19 +181,20 @@ pub struct TasksFilterQuery {
|
|||||||
#[deserr(default, error = DeserrQueryParamError<InvalidIndexUid>)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidIndexUid>)]
|
||||||
pub index_uids: OptionStarOrList<IndexUid>,
|
pub index_uids: OptionStarOrList<IndexUid>,
|
||||||
|
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterEnqueuedAt>, from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterEnqueuedAt>, try_from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
||||||
pub after_enqueued_at: OptionStarOr<OffsetDateTime>,
|
pub after_enqueued_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeEnqueuedAt>, from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeEnqueuedAt>, try_from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
||||||
pub before_enqueued_at: OptionStarOr<OffsetDateTime>,
|
pub before_enqueued_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterStartedAt>, from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterStartedAt>, try_from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
||||||
pub after_started_at: OptionStarOr<OffsetDateTime>,
|
pub after_started_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeStartedAt>, from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeStartedAt>, try_from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
||||||
pub before_started_at: OptionStarOr<OffsetDateTime>,
|
pub before_started_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterFinishedAt>, from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterFinishedAt>, try_from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
||||||
pub after_finished_at: OptionStarOr<OffsetDateTime>,
|
pub after_finished_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeFinishedAt>, from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeFinishedAt>, try_from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
||||||
pub before_finished_at: OptionStarOr<OffsetDateTime>,
|
pub before_finished_at: OptionStarOr<OffsetDateTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TasksFilterQuery {
|
impl TasksFilterQuery {
|
||||||
fn into_query(self) -> Query {
|
fn into_query(self) -> Query {
|
||||||
Query {
|
Query {
|
||||||
@ -235,7 +236,7 @@ impl TaskDeletionOrCancelationQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, DeserializeFromValue)]
|
#[derive(Debug, Deserr)]
|
||||||
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrQueryParamError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct TaskDeletionOrCancelationQuery {
|
pub struct TaskDeletionOrCancelationQuery {
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskUids>)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskUids>)]
|
||||||
@ -249,19 +250,20 @@ pub struct TaskDeletionOrCancelationQuery {
|
|||||||
#[deserr(default, error = DeserrQueryParamError<InvalidIndexUid>)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidIndexUid>)]
|
||||||
pub index_uids: OptionStarOrList<IndexUid>,
|
pub index_uids: OptionStarOrList<IndexUid>,
|
||||||
|
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterEnqueuedAt>, from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterEnqueuedAt>, try_from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
||||||
pub after_enqueued_at: OptionStarOr<OffsetDateTime>,
|
pub after_enqueued_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeEnqueuedAt>, from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeEnqueuedAt>, try_from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
||||||
pub before_enqueued_at: OptionStarOr<OffsetDateTime>,
|
pub before_enqueued_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterStartedAt>, from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterStartedAt>, try_from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
||||||
pub after_started_at: OptionStarOr<OffsetDateTime>,
|
pub after_started_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeStartedAt>, from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeStartedAt>, try_from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
||||||
pub before_started_at: OptionStarOr<OffsetDateTime>,
|
pub before_started_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterFinishedAt>, from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskAfterFinishedAt>, try_from(OptionStarOr<String>) = deserialize_date_after -> InvalidTaskDateError)]
|
||||||
pub after_finished_at: OptionStarOr<OffsetDateTime>,
|
pub after_finished_at: OptionStarOr<OffsetDateTime>,
|
||||||
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeFinishedAt>, from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
#[deserr(default, error = DeserrQueryParamError<InvalidTaskBeforeFinishedAt>, try_from(OptionStarOr<String>) = deserialize_date_before -> InvalidTaskDateError)]
|
||||||
pub before_finished_at: OptionStarOr<OffsetDateTime>,
|
pub before_finished_at: OptionStarOr<OffsetDateTime>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TaskDeletionOrCancelationQuery {
|
impl TaskDeletionOrCancelationQuery {
|
||||||
fn into_query(self) -> Query {
|
fn into_query(self) -> Query {
|
||||||
Query {
|
Query {
|
||||||
@ -284,7 +286,7 @@ impl TaskDeletionOrCancelationQuery {
|
|||||||
|
|
||||||
async fn cancel_tasks(
|
async fn cancel_tasks(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_CANCEL }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_CANCEL }>, Data<IndexScheduler>>,
|
||||||
params: QueryParameter<TaskDeletionOrCancelationQuery, DeserrQueryParamError>,
|
params: AwebQueryParameter<TaskDeletionOrCancelationQuery, DeserrQueryParamError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
@ -330,7 +332,7 @@ async fn cancel_tasks(
|
|||||||
|
|
||||||
async fn delete_tasks(
|
async fn delete_tasks(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_DELETE }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_DELETE }>, Data<IndexScheduler>>,
|
||||||
params: QueryParameter<TaskDeletionOrCancelationQuery, DeserrQueryParamError>,
|
params: AwebQueryParameter<TaskDeletionOrCancelationQuery, DeserrQueryParamError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
@ -383,7 +385,7 @@ pub struct AllTasks {
|
|||||||
|
|
||||||
async fn get_tasks(
|
async fn get_tasks(
|
||||||
index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_GET }>, Data<IndexScheduler>>,
|
index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_GET }>, Data<IndexScheduler>>,
|
||||||
params: QueryParameter<TasksFilterQuery, DeserrQueryParamError>,
|
params: AwebQueryParameter<TasksFilterQuery, DeserrQueryParamError>,
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
analytics: web::Data<dyn Analytics>,
|
analytics: web::Data<dyn Analytics>,
|
||||||
) -> Result<HttpResponse, ResponseError> {
|
) -> Result<HttpResponse, ResponseError> {
|
||||||
@ -498,7 +500,7 @@ pub fn deserialize_date_before(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use deserr::DeserializeFromValue;
|
use deserr::Deserr;
|
||||||
use meili_snap::snapshot;
|
use meili_snap::snapshot;
|
||||||
use meilisearch_types::deserr::DeserrQueryParamError;
|
use meilisearch_types::deserr::DeserrQueryParamError;
|
||||||
use meilisearch_types::error::{Code, ResponseError};
|
use meilisearch_types::error::{Code, ResponseError};
|
||||||
@ -507,7 +509,7 @@ mod tests {
|
|||||||
|
|
||||||
fn deserr_query_params<T>(j: &str) -> Result<T, ResponseError>
|
fn deserr_query_params<T>(j: &str) -> Result<T, ResponseError>
|
||||||
where
|
where
|
||||||
T: DeserializeFromValue<DeserrQueryParamError>,
|
T: Deserr<DeserrQueryParamError>,
|
||||||
{
|
{
|
||||||
let value = serde_urlencoded::from_str::<serde_json::Value>(j)
|
let value = serde_urlencoded::from_str::<serde_json::Value>(j)
|
||||||
.map_err(|e| ResponseError::from_msg(e.to_string(), Code::BadRequest))?;
|
.map_err(|e| ResponseError::from_msg(e.to_string(), Code::BadRequest))?;
|
||||||
|
@ -3,7 +3,7 @@ use std::collections::{BTreeMap, BTreeSet, HashSet};
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use deserr::DeserializeFromValue;
|
use deserr::Deserr;
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use meilisearch_types::deserr::DeserrJsonError;
|
use meilisearch_types::deserr::DeserrJsonError;
|
||||||
use meilisearch_types::error::deserr_codes::*;
|
use meilisearch_types::error::deserr_codes::*;
|
||||||
@ -29,7 +29,7 @@ pub const DEFAULT_CROP_MARKER: fn() -> String = || "…".to_string();
|
|||||||
pub const DEFAULT_HIGHLIGHT_PRE_TAG: fn() -> String = || "<em>".to_string();
|
pub const DEFAULT_HIGHLIGHT_PRE_TAG: fn() -> String = || "<em>".to_string();
|
||||||
pub const DEFAULT_HIGHLIGHT_POST_TAG: fn() -> String = || "</em>".to_string();
|
pub const DEFAULT_HIGHLIGHT_POST_TAG: fn() -> String = || "</em>".to_string();
|
||||||
|
|
||||||
#[derive(Debug, Clone, Default, PartialEq, Eq, DeserializeFromValue)]
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Deserr)]
|
||||||
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
#[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)]
|
||||||
pub struct SearchQuery {
|
pub struct SearchQuery {
|
||||||
#[deserr(default, error = DeserrJsonError<InvalidSearchQ>)]
|
#[deserr(default, error = DeserrJsonError<InvalidSearchQ>)]
|
||||||
@ -74,7 +74,7 @@ impl SearchQuery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, DeserializeFromValue)]
|
#[derive(Debug, Clone, PartialEq, Eq, Deserr)]
|
||||||
#[deserr(rename_all = camelCase)]
|
#[deserr(rename_all = camelCase)]
|
||||||
pub enum MatchingStrategy {
|
pub enum MatchingStrategy {
|
||||||
/// Remove query words from last to first
|
/// Remove query words from last to first
|
||||||
|
@ -138,7 +138,7 @@ async fn create_api_key_bad_expires_at() {
|
|||||||
snapshot!(code, @"400 Bad Request");
|
snapshot!(code, @"400 Bad Request");
|
||||||
snapshot!(json_string!(response), @r###"
|
snapshot!(json_string!(response), @r###"
|
||||||
{
|
{
|
||||||
"message": "Unknown field `expires_at`: expected one of `description`, `name`, `uid`, `actions`, `indexes`, `expiresAt`",
|
"message": "Unknown field `expires_at`: did you mean `expiresAt`? expected one of `description`, `name`, `uid`, `actions`, `indexes`, `expiresAt`",
|
||||||
"code": "bad_request",
|
"code": "bad_request",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#bad_request"
|
"link": "https://docs.meilisearch.com/errors#bad_request"
|
||||||
@ -150,7 +150,7 @@ async fn create_api_key_bad_expires_at() {
|
|||||||
snapshot!(code, @"400 Bad Request");
|
snapshot!(code, @"400 Bad Request");
|
||||||
snapshot!(json_string!(response), @r###"
|
snapshot!(json_string!(response), @r###"
|
||||||
{
|
{
|
||||||
"message": "Unknown field `expires_at`: expected one of `description`, `name`, `uid`, `actions`, `indexes`, `expiresAt`",
|
"message": "Unknown field `expires_at`: did you mean `expiresAt`? expected one of `description`, `name`, `uid`, `actions`, `indexes`, `expiresAt`",
|
||||||
"code": "bad_request",
|
"code": "bad_request",
|
||||||
"type": "invalid_request",
|
"type": "invalid_request",
|
||||||
"link": "https://docs.meilisearch.com/errors#bad_request"
|
"link": "https://docs.meilisearch.com/errors#bad_request"
|
||||||
|
@ -12,7 +12,7 @@ byteorder = "1.4.3"
|
|||||||
charabia = { version = "0.7.0", default-features = false }
|
charabia = { version = "0.7.0", default-features = false }
|
||||||
concat-arrays = "0.1.2"
|
concat-arrays = "0.1.2"
|
||||||
crossbeam-channel = "0.5.6"
|
crossbeam-channel = "0.5.6"
|
||||||
deserr = "0.3.0"
|
deserr = "0.4.1"
|
||||||
either = "1.8.0"
|
either = "1.8.0"
|
||||||
flatten-serde-json = { path = "../flatten-serde-json" }
|
flatten-serde-json = { path = "../flatten-serde-json" }
|
||||||
fst = "0.4.7"
|
fst = "0.4.7"
|
||||||
|
@ -2,7 +2,7 @@ use std::collections::{BTreeSet, HashMap, HashSet};
|
|||||||
use std::result::Result as StdResult;
|
use std::result::Result as StdResult;
|
||||||
|
|
||||||
use charabia::{Tokenizer, TokenizerBuilder};
|
use charabia::{Tokenizer, TokenizerBuilder};
|
||||||
use deserr::{DeserializeError, DeserializeFromValue};
|
use deserr::{DeserializeError, Deserr};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||||
use time::OffsetDateTime;
|
use time::OffsetDateTime;
|
||||||
@ -23,9 +23,9 @@ pub enum Setting<T> {
|
|||||||
NotSet,
|
NotSet,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T, E> DeserializeFromValue<E> for Setting<T>
|
impl<T, E> Deserr<E> for Setting<T>
|
||||||
where
|
where
|
||||||
T: DeserializeFromValue<E>,
|
T: Deserr<E>,
|
||||||
E: DeserializeError,
|
E: DeserializeError,
|
||||||
{
|
{
|
||||||
fn deserialize_from_value<V: deserr::IntoValue>(
|
fn deserialize_from_value<V: deserr::IntoValue>(
|
||||||
|
Loading…
Reference in New Issue
Block a user