fix serialization bug in settings

This commit is contained in:
marin postma 2021-06-23 15:25:56 +02:00
parent 0ebe3900e0
commit 322d6b8cfe
No known key found for this signature in database
GPG Key ID: 6088B7721C3E39F9

View File

@ -7,7 +7,7 @@ use crate::{error::ResponseError, index::Unchecked};
#[macro_export] #[macro_export]
macro_rules! make_setting_route { macro_rules! make_setting_route {
($route:literal, $type:ty, $attr:ident) => { ($route:literal, $type:ty, $attr:ident, $camelcase_attr:literal) => {
mod $attr { mod $attr {
use actix_web::{web, HttpResponse}; use actix_web::{web, HttpResponse};
@ -51,7 +51,9 @@ macro_rules! make_setting_route {
index_uid: actix_web::web::Path<String>, index_uid: actix_web::web::Path<String>,
) -> std::result::Result<HttpResponse, ResponseError> { ) -> std::result::Result<HttpResponse, ResponseError> {
let settings = data.settings(index_uid.into_inner()).await?; let settings = data.settings(index_uid.into_inner()).await?;
Ok(HttpResponse::Ok().json(settings.$attr)) let mut json = serde_json::json!(&settings);
let val = json[$camelcase_attr].take();
Ok(HttpResponse::Ok().json(val))
} }
} }
}; };
@ -60,43 +62,50 @@ macro_rules! make_setting_route {
make_setting_route!( make_setting_route!(
"/indexes/{index_uid}/settings/filterable-attributes", "/indexes/{index_uid}/settings/filterable-attributes",
std::collections::HashSet<String>, std::collections::HashSet<String>,
filterable_attributes filterable_attributes,
"filterableAttributes"
); );
make_setting_route!( make_setting_route!(
"/indexes/{index_uid}/settings/displayed-attributes", "/indexes/{index_uid}/settings/displayed-attributes",
Vec<String>, Vec<String>,
displayed_attributes displayed_attributes,
"displayedAttributes"
); );
make_setting_route!( make_setting_route!(
"/indexes/{index_uid}/settings/searchable-attributes", "/indexes/{index_uid}/settings/searchable-attributes",
Vec<String>, Vec<String>,
searchable_attributes searchable_attributes,
"searchableAttributes"
); );
make_setting_route!( make_setting_route!(
"/indexes/{index_uid}/settings/stop-words", "/indexes/{index_uid}/settings/stop-words",
std::collections::BTreeSet<String>, std::collections::BTreeSet<String>,
stop_words stop_words,
"stopWords"
); );
make_setting_route!( make_setting_route!(
"/indexes/{index_uid}/settings/synonyms", "/indexes/{index_uid}/settings/synonyms",
std::collections::BTreeMap<String, Vec<String>>, std::collections::BTreeMap<String, Vec<String>>,
synonyms synonyms,
"synonyms"
); );
make_setting_route!( make_setting_route!(
"/indexes/{index_uid}/settings/distinct-attribute", "/indexes/{index_uid}/settings/distinct-attribute",
String, String,
distinct_attribute distinct_attribute,
"distinctAttribute"
); );
make_setting_route!( make_setting_route!(
"/indexes/{index_uid}/settings/ranking-rules", "/indexes/{index_uid}/settings/ranking-rules",
Vec<String>, Vec<String>,
ranking_rules ranking_rules,
"rankingRules"
); );
macro_rules! create_services { macro_rules! create_services {