diff --git a/src/core_api.cpp b/src/core_api.cpp index 88e8d036..e82b5963 100644 --- a/src/core_api.cpp +++ b/src/core_api.cpp @@ -1902,9 +1902,9 @@ bool get_stopwords(const std::shared_ptr& req, const std::shared_ptr& req, const std::shared_ptr& req, const std::shared_ptr& res) { - const std::string & stopword_name = req->params["stopword_name"]; + const std::string & stopword_name = req->params["name"]; StopwordsManager& stopwordManager = StopwordsManager::get_instance(); spp::sparse_hash_set stopwords; @@ -1980,9 +1980,9 @@ bool del_stopword(const std::shared_ptr& req, const std::shared_ptrset_200(res_json.dump()); diff --git a/src/stopwords_manager.cpp b/src/stopwords_manager.cpp index f24cb8ab..af72c39f 100644 --- a/src/stopwords_manager.cpp +++ b/src/stopwords_manager.cpp @@ -28,6 +28,7 @@ Option StopwordsManager::upsert_stopword(const std::string& stopword_name, const char* STOPWORD_VALUES = "stopwords"; const char* STOPWORD_LOCALE = "locale"; + std::string locale = ""; if(stopwords_json.count(STOPWORD_VALUES) == 0){ return Option(400, (std::string("Parameter `") + STOPWORD_VALUES + "` is required")); @@ -37,12 +38,11 @@ Option StopwordsManager::upsert_stopword(const std::string& stopword_name, return Option(400, (std::string("Parameter `") + STOPWORD_VALUES + "` is required as string array value")); } - if(stopwords_json.count(STOPWORD_LOCALE) == 0) { - return Option(400, (std::string("Parameter `") + STOPWORD_LOCALE + "` is required")); - } - - if(!stopwords_json[STOPWORD_LOCALE].is_string()) { - return Option(400, (std::string("Parameter `") + STOPWORD_LOCALE + "` is required as string value")); + if(stopwords_json.count(STOPWORD_LOCALE) != 0) { + if (!stopwords_json[STOPWORD_LOCALE].is_string()) { + return Option(400, (std::string("Parameter `") + STOPWORD_LOCALE + "` is required as string value")); + } + locale = stopwords_json[STOPWORD_LOCALE]; } if(write_to_store) { @@ -55,7 +55,6 @@ Option StopwordsManager::upsert_stopword(const std::string& stopword_name, std::vector tokens; spp::sparse_hash_set stopwords_set; const auto& stopwords = stopwords_json[STOPWORD_VALUES]; - const auto& locale = stopwords_json[STOPWORD_LOCALE]; for (const auto &stopword: stopwords.items()) { const auto& val = stopword.value().get(); diff --git a/test/stopwords_manager_test.cpp b/test/stopwords_manager_test.cpp index 8653af19..bb06eb10 100644 --- a/test/stopwords_manager_test.cpp +++ b/test/stopwords_manager_test.cpp @@ -328,20 +328,8 @@ TEST_F(StopwordsManagerTest, StopwordsValidation) { std::shared_ptr req = std::make_shared(); std::shared_ptr res = std::make_shared(nullptr); - auto stopword_value = R"( - {"stopwords": ["america", "europe"]} - )"_json; - - req->params["collection"] = "coll1"; - req->params["name"] = "continents"; - req->body = stopword_value.dump(); - - auto result = put_upsert_stopword(req, res); - ASSERT_EQ(400, res->status_code); - ASSERT_EQ("{\"message\": \"Parameter `locale` is required\"}", res->body); - //with a typo - stopword_value = R"( + auto stopword_value = R"( {"stopword": ["america", "europe"], "locale": "en"} )"_json; @@ -349,7 +337,7 @@ TEST_F(StopwordsManagerTest, StopwordsValidation) { req->params["name"] = "continents"; req->body = stopword_value.dump(); - result = put_upsert_stopword(req, res); + auto result = put_upsert_stopword(req, res); ASSERT_EQ(400, res->status_code); ASSERT_STREQ("{\"message\": \"Parameter `stopwords` is required\"}", res->body.c_str());