summaryrefslogtreecommitdiff
path: root/redfish-core/include
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-06-27 22:45:55 +0300
committerEd Tanous <ed@tanous.net>2023-06-13 20:48:37 +0300
commite2616cc5d2093715bbbb5a7ff6aa0c86b2c466d4 (patch)
tree366c7af45e3f71b14aaab6a93841a7bd7c64041f /redfish-core/include
parent8dab0f580cd31638bdf1a6ed1cef249fc6e1a14d (diff)
downloadbmcweb-e2616cc5d2093715bbbb5a7ff6aa0c86b2c466d4.tar.xz
Make propertyValueNotInList typesafe
The error codes for this function accept a string_view, which has caused a number of cases of users of this function to call dump() to_string() and all manner of other conversions. Considering that dump() is something that's difficult to call correctly, and overly wordy, it would be ideal if the message code just handled that for us. Therefore, this commit changes the prototype to include a nlohmann::json object as an argument instead of string_view, then audits the codebase for all uses, and moves them to a more normalized usage, which allows the calling code to call "dump" for them. Tested: PATCH /redfish/v1/SessionService {"SessionTimeout": 1} Returns the PropertyValueNotInList error as it did before. Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: If62909072db1f067ad1f8aa590bb716c84181219
Diffstat (limited to 'redfish-core/include')
-rw-r--r--redfish-core/include/error_messages.hpp5
-rw-r--r--redfish-core/include/utils/json_utils.hpp6
2 files changed, 3 insertions, 8 deletions
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index b8439705bb..99e9ae8f37 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -263,12 +263,11 @@ void propertyValueFormatError(crow::Response& res, std::string_view arg1,
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueNotInList formatted to JSON */
-nlohmann::json propertyValueNotInList(std::string_view arg1,
+nlohmann::json propertyValueNotInList(const nlohmann::json& arg1,
std::string_view arg2);
-void propertyValueNotInList(crow::Response& res, std::string_view arg1,
+void propertyValueNotInList(crow::Response& res, const nlohmann::json& arg1,
std::string_view arg2);
-
/**
* @brief Formats PropertyValueOutOfRange message into JSON
* Message body: "The value '%1' for the property %2 is not in the supported
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index 5ecce0a823..7c701428af 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -278,11 +278,7 @@ bool unpackValue(nlohmann::json& jsonValue, std::string_view key,
}
else if (ec == UnpackErrorCode::outOfRange)
{
- messages::propertyValueNotInList(
- res,
- jsonValue.dump(2, ' ', true,
- nlohmann::json::error_handler_t::replace),
- key);
+ messages::propertyValueNotInList(res, jsonValue, key);
}
return false;
}