diff --git a/meilisearch-http/src/routes/index.rs b/meilisearch-http/src/routes/index.rs index 7e6eb4716..006ffd348 100644 --- a/meilisearch-http/src/routes/index.rs +++ b/meilisearch-http/src/routes/index.rs @@ -116,9 +116,8 @@ pub async fn get_index(ctx: Request) -> SResult { #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase", deny_unknown_fields)] struct IndexCreateRequest { - name: String, + name: Option, uid: Option, - // schema: Option, } #[derive(Debug, Serialize)] @@ -138,6 +137,10 @@ pub async fn create_index(mut ctx: Request) -> SResult { .await .map_err(ResponseError::bad_request)?; + if let (None, None) = (body.name.clone(), body.uid.clone()) { + return Err(ResponseError::bad_request("Index creation must have an uid")); + } + let db = &ctx.state().db; let uid = match body.uid { @@ -157,14 +160,11 @@ pub async fn create_index(mut ctx: Request) -> SResult { let mut writer = db.main_write_txn().map_err(ResponseError::internal)?; - created_index - .main - .put_name(&mut writer, &body.name) - .map_err(ResponseError::internal)?; + let name = body.name.unwrap_or(uid.clone()); - // let schema: Option = body.schema.clone().map(Into::into); - // let mut response_update_id = None; - // if let Some(schema) = schema { + created_index.main + .put_name(&mut writer, &name) + .map_err(ResponseError::internal)?; writer.commit().map_err(ResponseError::internal)?;