Split up findNavigationReference
findNavigationReference handles a couple different types. Split it up
into the relevant types.
Tested: Unit tests pass. Pretty good coverage for this section of code.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I0c601a0779c23050b7803e4691334243485c8d29
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp
index e5402d5..7be2a40 100644
--- a/redfish-core/include/utils/query_param.hpp
+++ b/redfish-core/include/utils/query_param.hpp
@@ -525,6 +525,16 @@
}
};
+inline void findNavigationReferencesInArrayRecursive(
+ ExpandType eType, nlohmann::json::array_t* array,
+ const nlohmann::json::json_pointer& p, int depth, int skipDepth,
+ bool inLinks, std::vector<ExpandNode>& out);
+
+inline void findNavigationReferencesInObjectRecursive(
+ ExpandType eType, nlohmann::json::object_t* obj,
+ const nlohmann::json::json_pointer& p, int depth, int skipDepth,
+ bool inLinks, std::vector<ExpandNode>& out);
+
// Walks a json object looking for Redfish NavigationReference entries that
// might need resolved. It recursively walks the jsonResponse object, looking
// for links at every level, and returns a list (out) of locations within the
@@ -546,16 +556,8 @@
jsonResponse.get_ptr<nlohmann::json::array_t*>();
if (array != nullptr)
{
- size_t index = 0;
- // For arrays, walk every element in the array
- for (auto& element : *array)
- {
- nlohmann::json::json_pointer newPtr = p / index;
- BMCWEB_LOG_DEBUG << "Traversing response at " << newPtr.to_string();
- findNavigationReferencesRecursive(eType, element, newPtr, depth,
- skipDepth, inLinks, out);
- index++;
- }
+ findNavigationReferencesInArrayRecursive(eType, array, p, depth,
+ skipDepth, inLinks, out);
}
nlohmann::json::object_t* obj =
jsonResponse.get_ptr<nlohmann::json::object_t*>();
@@ -563,6 +565,32 @@
{
return;
}
+ findNavigationReferencesInObjectRecursive(eType, obj, p, depth, skipDepth,
+ inLinks, out);
+}
+
+inline void findNavigationReferencesInArrayRecursive(
+ ExpandType eType, nlohmann::json::array_t* array,
+ const nlohmann::json::json_pointer& p, int depth, int skipDepth,
+ bool inLinks, std::vector<ExpandNode>& out)
+{
+ size_t index = 0;
+ // For arrays, walk every element in the array
+ for (auto& element : *array)
+ {
+ nlohmann::json::json_pointer newPtr = p / index;
+ BMCWEB_LOG_DEBUG << "Traversing response at " << newPtr.to_string();
+ findNavigationReferencesRecursive(eType, element, newPtr, depth,
+ skipDepth, inLinks, out);
+ index++;
+ }
+}
+
+inline void findNavigationReferencesInObjectRecursive(
+ ExpandType eType, nlohmann::json::object_t* obj,
+ const nlohmann::json::json_pointer& p, int depth, int skipDepth,
+ bool inLinks, std::vector<ExpandNode>& out)
+{
// Navigation References only ever have a single element
if (obj->size() == 1)
{