Make redfish::messages rely on typesafe structures
The previous patches modified these fields one at a time, for the cases
where we had code calling these in odd ways. This commit goes and
effects the same change on the rest of the message handlers where it
makes sense.
Any input to a message function that mentions a "value" replaces the
value with a nlohmann::json object, to make calling this code easier.
The one exception is StringValueTooLong, which by definition, requires
the input value to be a string, so that is left as string_view
intentionally.
Tested: Dead unused code. Code compiles.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I00b9804b2aadf5584032be91a0ee53b9a94a7430
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index c49ac33..6f1e4e8 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -85,11 +85,12 @@
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message ActionParameterValueFormatError formatted to JSON */
-nlohmann::json actionParameterValueFormatError(std::string_view arg1,
+nlohmann::json actionParameterValueFormatError(const nlohmann::json& arg1,
std::string_view arg2,
std::string_view arg3);
-void actionParameterValueFormatError(crow::Response& res, std::string_view arg1,
+void actionParameterValueFormatError(crow::Response& res,
+ const nlohmann::json& arg1,
std::string_view arg2,
std::string_view arg3);
@@ -277,10 +278,10 @@
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message PropertyValueExternalConflict formatted to JSON */
-nlohmann::json propertyValueOutOfRange(std::string_view arg1,
+nlohmann::json propertyValueOutOfRange(const nlohmann::json& arg1,
std::string_view arg2);
-void propertyValueOutOfRange(crow::Response& res, std::string_view arg1,
+void propertyValueOutOfRange(crow::Response& res, const nlohmann::json& arg1,
std::string_view arg2);
/**
@@ -457,11 +458,11 @@
*
* @returns Message PropertyValueResourceConflict to JSON */
nlohmann::json propertyValueResourceConflict(std::string_view arg1,
- std::string_view arg2,
+ const nlohmann::json& arg2,
boost::urls::url_view arg3);
void propertyValueResourceConflict(crow::Response& res, std::string_view arg1,
- std::string_view arg2,
+ const nlohmann::json& arg2,
boost::urls::url_view arg3);
/**
@@ -475,10 +476,10 @@
*
* @returns Message PropertyValueExternalConflict formatted to JSON */
nlohmann::json propertyValueExternalConflict(std::string_view arg1,
- std::string_view arg2);
+ const nlohmann::json& arg2);
void propertyValueExternalConflict(crow::Response& res, std::string_view arg1,
- std::string_view arg2);
+ const nlohmann::json& arg2);
/**
* @brief Formats PropertyValueIncorrect message into JSON
@@ -625,10 +626,11 @@
* @param[in] arg2 Parameter of message that will replace %2 in its body.
*
* @returns Message QueryParameterValueTypeError formatted to JSON */
-nlohmann::json queryParameterValueTypeError(std::string_view arg1,
+nlohmann::json queryParameterValueTypeError(const nlohmann::json& arg1,
std::string_view arg2);
-void queryParameterValueTypeError(crow::Response& res, std::string_view arg1,
+void queryParameterValueTypeError(crow::Response& res,
+ const nlohmann::json& arg1,
std::string_view arg2);
/**
@@ -839,11 +841,12 @@
* @param[in] arg3 Parameter of message that will replace %3 in its body.
*
* @returns Message ActionParameterValueTypeError formatted to JSON */
-nlohmann::json actionParameterValueTypeError(std::string_view arg1,
+nlohmann::json actionParameterValueTypeError(const nlohmann::json& arg1,
std::string_view arg2,
std::string_view arg3);
-void actionParameterValueTypeError(crow::Response& res, std::string_view arg1,
+void actionParameterValueTypeError(crow::Response& res,
+ const nlohmann::json& arg1,
std::string_view arg2,
std::string_view arg3);
@@ -944,10 +947,10 @@
*
* @returns Message PropertyValueModified formatted to JSON */
nlohmann::json propertyValueModified(std::string_view arg1,
- std::string_view arg2);
+ const nlohmann::json& arg2);
void propertyValueModified(crow::Response& res, std::string_view arg1,
- std::string_view arg2);
+ const nlohmann::json& arg2);
/**
* @brief Formats AccountNotModified message into JSON
@@ -969,10 +972,11 @@
*
* @returns Message QueryParameterValueFormatError formatted to JSON */
-nlohmann::json queryParameterValueFormatError(std::string_view arg1,
+nlohmann::json queryParameterValueFormatError(const nlohmann::json& arg1,
std::string_view arg2);
-void queryParameterValueFormatError(crow::Response& res, std::string_view arg1,
+void queryParameterValueFormatError(crow::Response& res,
+ const nlohmann::json& arg1,
std::string_view arg2);
/**
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index c397e1f..1742d23 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -223,16 +223,19 @@
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterValueFormatError(std::string_view arg1,
+nlohmann::json actionParameterValueFormatError(const nlohmann::json& arg1,
std::string_view arg2,
std::string_view arg3)
{
+ std::string arg1Str = arg1.dump(2, ' ', true,
+ nlohmann::json::error_handler_t::replace);
return getLog(
redfish::registries::base::Index::actionParameterValueFormatError,
- std::to_array({arg1, arg2, arg3}));
+ std::to_array<std::string_view>({arg1Str, arg2, arg3}));
}
-void actionParameterValueFormatError(crow::Response& res, std::string_view arg1,
+void actionParameterValueFormatError(crow::Response& res,
+ const nlohmann::json& arg1,
std::string_view arg2,
std::string_view arg3)
{
@@ -526,14 +529,16 @@
* See header file for more information
* @endinternal
*/
-nlohmann::json propertyValueOutOfRange(std::string_view arg1,
+nlohmann::json propertyValueOutOfRange(const nlohmann::json& arg1,
std::string_view arg2)
{
+ std::string arg1Str = arg1.dump(2, ' ', true,
+ nlohmann::json::error_handler_t::replace);
return getLog(redfish::registries::base::Index::propertyValueOutOfRange,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1Str, arg2}));
}
-void propertyValueOutOfRange(crow::Response& res, std::string_view arg1,
+void propertyValueOutOfRange(crow::Response& res, const nlohmann::json& arg1,
std::string_view arg2)
{
res.result(boost::beast::http::status::bad_request);
@@ -803,16 +808,19 @@
* @endinternal
*/
nlohmann::json propertyValueResourceConflict(std::string_view arg1,
- std::string_view arg2,
+ const nlohmann::json& arg2,
boost::urls::url_view arg3)
{
+ std::string arg2Str = arg2.dump(2, ' ', true,
+ nlohmann::json::error_handler_t::replace);
+
return getLog(
redfish::registries::base::Index::propertyValueResourceConflict,
- std::to_array<std::string_view>({arg1, arg2, arg3.buffer()}));
+ std::to_array<std::string_view>({arg1, arg2Str, arg3.buffer()}));
}
void propertyValueResourceConflict(crow::Response& res, std::string_view arg1,
- std::string_view arg2,
+ const nlohmann::json& arg2,
boost::urls::url_view arg3)
{
res.result(boost::beast::http::status::conflict);
@@ -828,15 +836,18 @@
* @endinternal
*/
nlohmann::json propertyValueExternalConflict(std::string_view arg1,
- std::string_view arg2)
+ const nlohmann::json& arg2)
{
+ std::string arg2Str = arg2.dump(2, ' ', true,
+ nlohmann::json::error_handler_t::replace);
+
return getLog(
redfish::registries::base::Index::propertyValueExternalConflict,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1, arg2Str}));
}
void propertyValueExternalConflict(crow::Response& res, std::string_view arg1,
- std::string_view arg2)
+ const nlohmann::json& arg2)
{
res.result(boost::beast::http::status::conflict);
addMessageToErrorJson(res.jsonValue,
@@ -1066,15 +1077,18 @@
* See header file for more information
* @endinternal
*/
-nlohmann::json queryParameterValueTypeError(std::string_view arg1,
+nlohmann::json queryParameterValueTypeError(const nlohmann::json& arg1,
std::string_view arg2)
{
+ std::string arg1Str = arg1.dump(2, ' ', true,
+ nlohmann::json::error_handler_t::replace);
return getLog(
redfish::registries::base::Index::queryParameterValueTypeError,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1Str, arg2}));
}
-void queryParameterValueTypeError(crow::Response& res, std::string_view arg1,
+void queryParameterValueTypeError(crow::Response& res,
+ const nlohmann::json& arg1,
std::string_view arg2)
{
res.result(boost::beast::http::status::bad_request);
@@ -1415,16 +1429,19 @@
* See header file for more information
* @endinternal
*/
-nlohmann::json actionParameterValueTypeError(std::string_view arg1,
+nlohmann::json actionParameterValueTypeError(const nlohmann::json& arg1,
std::string_view arg2,
std::string_view arg3)
{
+ std::string arg1Str = arg1.dump(2, ' ', true,
+ nlohmann::json::error_handler_t::replace);
return getLog(
redfish::registries::base::Index::actionParameterValueTypeError,
- std::to_array({arg1, arg2, arg3}));
+ std::to_array<std::string_view>({arg1Str, arg2, arg3}));
}
-void actionParameterValueTypeError(crow::Response& res, std::string_view arg1,
+void actionParameterValueTypeError(crow::Response& res,
+ const nlohmann::json& arg1,
std::string_view arg2, std::string_view arg3)
{
res.result(boost::beast::http::status::bad_request);
@@ -1590,14 +1607,16 @@
* @endinternal
*/
nlohmann::json propertyValueModified(std::string_view arg1,
- std::string_view arg2)
+ const nlohmann::json& arg2)
{
+ std::string arg2Str = arg2.dump(2, ' ', true,
+ nlohmann::json::error_handler_t::replace);
return getLog(redfish::registries::base::Index::propertyValueModified,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1, arg2Str}));
}
void propertyValueModified(crow::Response& res, std::string_view arg1,
- std::string_view arg2)
+ const nlohmann::json& arg2)
{
res.result(boost::beast::http::status::ok);
addMessageToJson(res.jsonValue, propertyValueModified(arg1, arg2), arg1);
@@ -1628,15 +1647,18 @@
* See header file for more information
* @endinternal
*/
-nlohmann::json queryParameterValueFormatError(std::string_view arg1,
+nlohmann::json queryParameterValueFormatError(const nlohmann::json& arg1,
std::string_view arg2)
{
+ std::string arg1Str = arg1.dump(2, ' ', true,
+ nlohmann::json::error_handler_t::replace);
return getLog(
redfish::registries::base::Index::queryParameterValueFormatError,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1Str, arg2}));
}
-void queryParameterValueFormatError(crow::Response& res, std::string_view arg1,
+void queryParameterValueFormatError(crow::Response& res,
+ const nlohmann::json& arg1,
std::string_view arg2)
{
res.result(boost::beast::http::status::bad_request);