Parse number types from the base registry
Rather than maintaining a list of arguments that are numbers (which is
error prone), update the script to just trust that the few parameters
labeled in Redfish as numbers should in fact show up in the API as
numbers.
Functionally this changes the APIs for only a few error messages, only
one of which (StringValueTooShort) is used and that usage was added
recently.
Tested: SRV passes.
Change-Id: I580523ecc0263688738bcb7f7925913e40e2a113
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/redfish-core/include/error_messages.hpp b/redfish-core/include/error_messages.hpp
index b9fd429..98b3988 100644
--- a/redfish-core/include/error_messages.hpp
+++ b/redfish-core/include/error_messages.hpp
@@ -219,9 +219,9 @@
* @param[in] arg1 Parameter of message that will replace %1 in its body.
*
* @returns Message InvalidJSON formatted to JSON */
-nlohmann::json::object_t invalidJSON(std::string_view arg1);
+nlohmann::json::object_t invalidJSON(uint64_t arg1);
-void invalidJSON(crow::Response& res, std::string_view arg1);
+void invalidJSON(crow::Response& res, uint64_t arg1);
/**
* @brief Formats EmptyJSON message into JSON
@@ -412,10 +412,10 @@
*
* @returns Message ArraySizeTooShort formatted to JSON */
nlohmann::json::object_t arraySizeTooShort(std::string_view arg1,
- std::string_view arg2);
+ uint64_t arg2);
void arraySizeTooShort(crow::Response& res, std::string_view arg1,
- std::string_view arg2);
+ uint64_t arg2);
/**
* @brief Formats QueryParameterValueTypeError message into JSON
@@ -960,10 +960,10 @@
*
* @returns Message StringValueTooShort formatted to JSON */
nlohmann::json::object_t stringValueTooShort(std::string_view arg1,
- std::string_view arg2);
+ uint64_t arg2);
void stringValueTooShort(crow::Response& res, std::string_view arg1,
- std::string_view arg2);
+ uint64_t arg2);
/**
* @brief Formats SessionTerminated message into JSON
diff --git a/redfish-core/include/resource_messages.hpp b/redfish-core/include/resource_messages.hpp
index 98290ee..be642e9 100644
--- a/redfish-core/include/resource_messages.hpp
+++ b/redfish-core/include/resource_messages.hpp
@@ -38,16 +38,16 @@
std::string_view arg2);
nlohmann::json::object_t resourceErrorThresholdExceeded(std::string_view arg1,
- std::string_view arg2);
+ uint64_t arg2);
nlohmann::json::object_t resourceErrorThresholdCleared(std::string_view arg1,
- std::string_view arg2);
+ uint64_t arg2);
-nlohmann::json::object_t resourceWarningThresholdExceeded(
- std::string_view arg1, std::string_view arg2);
+nlohmann::json::object_t resourceWarningThresholdExceeded(std::string_view arg1,
+ uint64_t arg2);
nlohmann::json::object_t resourceWarningThresholdCleared(std::string_view arg1,
- std::string_view arg2);
+ uint64_t arg2);
nlohmann::json::object_t resourceStatusChangedOK(std::string_view arg1,
std::string_view arg2);
diff --git a/redfish-core/lib/aggregation_service.hpp b/redfish-core/lib/aggregation_service.hpp
index f503459..affe292 100644
--- a/redfish-core/lib/aggregation_service.hpp
+++ b/redfish-core/lib/aggregation_service.hpp
@@ -238,7 +238,7 @@
if (field->empty())
{
- messages::stringValueTooShort(res, fieldName, "1");
+ messages::stringValueTooShort(res, fieldName, 1);
return false;
}
diff --git a/redfish-core/src/error_messages.cpp b/redfish-core/src/error_messages.cpp
index 729cbd0..18ca966 100644
--- a/redfish-core/src/error_messages.cpp
+++ b/redfish-core/src/error_messages.cpp
@@ -356,13 +356,14 @@
* See header file for more information
* @endinternal
*/
-nlohmann::json::object_t invalidJSON(std::string_view arg1)
+nlohmann::json::object_t invalidJSON(uint64_t arg1)
{
+ std::string arg1Str = std::to_string(arg1);
return getLog(redfish::registries::Base::Index::invalidJSON,
- std::to_array({arg1}));
+ std::to_array<std::string_view>({arg1Str}));
}
-void invalidJSON(crow::Response& res, std::string_view arg1)
+void invalidJSON(crow::Response& res, uint64_t arg1)
{
res.result(boost::beast::http::status::bad_request);
addMessageToErrorJson(res.jsonValue, invalidJSON(arg1));
@@ -639,15 +640,15 @@
* See header file for more information
* @endinternal
*/
-nlohmann::json::object_t arraySizeTooShort(std::string_view arg1,
- std::string_view arg2)
+nlohmann::json::object_t arraySizeTooShort(std::string_view arg1, uint64_t arg2)
{
+ std::string arg2Str = std::to_string(arg2);
return getLog(redfish::registries::Base::Index::arraySizeTooShort,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1, arg2Str}));
}
void arraySizeTooShort(crow::Response& res, std::string_view arg1,
- std::string_view arg2)
+ uint64_t arg2)
{
res.result(boost::beast::http::status::bad_request);
addMessageToErrorJson(res.jsonValue, arraySizeTooShort(arg1, arg2));
@@ -1533,14 +1534,15 @@
* @endinternal
*/
nlohmann::json::object_t stringValueTooShort(std::string_view arg1,
- std::string_view arg2)
+ uint64_t arg2)
{
+ std::string arg2Str = std::to_string(arg2);
return getLog(redfish::registries::Base::Index::stringValueTooShort,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1, arg2Str}));
}
void stringValueTooShort(crow::Response& res, std::string_view arg1,
- std::string_view arg2)
+ uint64_t arg2)
{
res.result(boost::beast::http::status::bad_request);
addMessageToErrorJson(res.jsonValue, stringValueTooShort(arg1, arg2));
diff --git a/redfish-core/src/resource_messages.cpp b/redfish-core/src/resource_messages.cpp
index 74d8bd0..67fa51c 100644
--- a/redfish-core/src/resource_messages.cpp
+++ b/redfish-core/src/resource_messages.cpp
@@ -113,11 +113,12 @@
* @endinternal
*/
nlohmann::json::object_t resourceErrorThresholdExceeded(std::string_view arg1,
- std::string_view arg2)
+ uint64_t arg2)
{
+ std::string arg2Str = std::to_string(arg2);
return getLog(redfish::registries::ResourceEvent::Index::
resourceErrorThresholdExceeded,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1, arg2Str}));
}
/**
@@ -128,11 +129,12 @@
* @endinternal
*/
nlohmann::json::object_t resourceErrorThresholdCleared(std::string_view arg1,
- std::string_view arg2)
+ uint64_t arg2)
{
+ std::string arg2Str = std::to_string(arg2);
return getLog(redfish::registries::ResourceEvent::Index::
resourceErrorThresholdCleared,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1, arg2Str}));
}
/**
@@ -143,11 +145,12 @@
* @endinternal
*/
nlohmann::json::object_t resourceWarningThresholdExceeded(std::string_view arg1,
- std::string_view arg2)
+ uint64_t arg2)
{
+ std::string arg2Str = std::to_string(arg2);
return getLog(redfish::registries::ResourceEvent::Index::
resourceWarningThresholdExceeded,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1, arg2Str}));
}
/**
@@ -158,11 +161,12 @@
* @endinternal
*/
nlohmann::json::object_t resourceWarningThresholdCleared(std::string_view arg1,
- std::string_view arg2)
+ uint64_t arg2)
{
+ std::string arg2Str = std::to_string(arg2);
return getLog(redfish::registries::ResourceEvent::Index::
resourceWarningThresholdCleared,
- std::to_array({arg1, arg2}));
+ std::to_array<std::string_view>({arg1, arg2Str}));
}
/**
diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py
index 6f97bc1..7b315a8 100755
--- a/scripts/parse_registries.py
+++ b/scripts/parse_registries.py
@@ -312,12 +312,6 @@
"QueryParameterValueFormatError": [1],
"QueryParameterValueTypeError": [1],
},
- "uint64_t": {
- "ArraySizeTooLong": [2],
- "InvalidIndex": [1],
- "StringValueTooLong": [2],
- "TaskProgressChanged": [2],
- },
}
out = ""
@@ -326,6 +320,8 @@
for arg_index, arg in enumerate(entry.get("ParamTypes", [])):
arg_index += 1
typename = "std::string_view"
+ if arg == "number":
+ typename = "uint64_t"
for typestring, entries in arg_nonstring_types.items():
if arg_index in entries.get(entry_id, []):
typename = typestring