Boost::urls::format
Boost 1.82 dropped a lovely new toy, boost::urls::format, which is a lot
like our urlFromPieces method, but better in that it makes the resulting
uris more readable, and allows doing things like fragments in a single
line instead of multiple. We should prefer it in some cases.
Tested:
Redfish service validator passes.
Spot checks of URLs work as expected.
Unit tests pass.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ia7b38f0a95771c862507e7d5b4aa68aa1c98403c
diff --git a/redfish-core/lib/roles.hpp b/redfish-core/lib/roles.hpp
index a3382e8..784f716 100644
--- a/redfish-core/lib/roles.hpp
+++ b/redfish-core/lib/roles.hpp
@@ -20,6 +20,7 @@
#include "query.hpp"
#include "registries/privilege_registry.hpp"
+#include <boost/url/format.hpp>
#include <sdbusplus/asio/property.hpp>
#include <variant>
@@ -93,8 +94,8 @@
asyncResp->res.jsonValue["IsPredefined"] = true;
asyncResp->res.jsonValue["Id"] = roleId;
asyncResp->res.jsonValue["RoleId"] = roleId;
- asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
- "redfish", "v1", "AccountService", "Roles", roleId);
+ asyncResp->res.jsonValue["@odata.id"] =
+ boost::urls::format("/redfish/v1/AccountService/Roles/{}", roleId);
asyncResp->res.jsonValue["AssignedPrivileges"] = std::move(privArray);
});
}
@@ -137,8 +138,8 @@
if (!role.empty())
{
nlohmann::json::object_t member;
- member["@odata.id"] = crow::utility::urlFromPieces(
- "redfish", "v1", "AccountService", "Roles", role);
+ member["@odata.id"] = boost::urls::format(
+ "/redfish/v1/AccountService/Roles/{}", role);
memberArray.emplace_back(std::move(member));
}
}