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/update_service.hpp b/redfish-core/lib/update_service.hpp
index b6c0487..5f46d0a 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -28,6 +28,7 @@
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/system/error_code.hpp>
+#include <boost/url/format.hpp>
#include <sdbusplus/asio/property.hpp>
#include <sdbusplus/bus/match.hpp>
#include <sdbusplus/unpack_properties.hpp>
@@ -905,9 +906,8 @@
nlohmann::json& members = asyncResp->res.jsonValue["Members"];
nlohmann::json::object_t member;
- member["@odata.id"] = crow::utility::urlFromPieces(
- "redfish", "v1", "UpdateService", "FirmwareInventory",
- swId);
+ member["@odata.id"] = boost::urls::format(
+ "/redfish/v1/UpdateService/FirmwareInventory/{}", swId);
members.emplace_back(std::move(member));
asyncResp->res.jsonValue["Members@odata.count"] =
members.size();
@@ -1029,8 +1029,8 @@
std::shared_ptr<std::string> swId =
std::make_shared<std::string>(param);
- asyncResp->res.jsonValue["@odata.id"] = crow::utility::urlFromPieces(
- "redfish", "v1", "UpdateService", "FirmwareInventory", *swId);
+ asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
+ "/redfish/v1/UpdateService/FirmwareInventory/{}", *swId);
constexpr std::array<std::string_view, 1> interfaces = {
"xyz.openbmc_project.Software.Version"};
@@ -1072,9 +1072,10 @@
{
BMCWEB_LOG_ERROR << "Input swID " << *swId << " not found!";
messages::resourceMissingAtURI(
- asyncResp->res, crow::utility::urlFromPieces(
- "redfish", "v1", "UpdateService",
- "FirmwareInventory", *swId));
+ asyncResp->res,
+ boost::urls::format(
+ "/redfish/v1/UpdateService/FirmwareInventory/{}",
+ *swId));
return;
}
asyncResp->res.jsonValue["@odata.type"] =