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/redfish_v1.hpp b/redfish-core/lib/redfish_v1.hpp
index b3174fb..b7a1f4c 100644
--- a/redfish-core/lib/redfish_v1.hpp
+++ b/redfish-core/lib/redfish_v1.hpp
@@ -9,6 +9,8 @@
#include "schemas.hpp"
#include "utility.hpp"
+#include <boost/url/format.hpp>
+
#include <string>
namespace redfish
@@ -86,8 +88,8 @@
for (std::string_view schema : schemas)
{
nlohmann::json::object_t member;
- member["@odata.id"] = crow::utility::urlFromPieces(
- "redfish", "v1", "JsonSchemas", schema);
+ member["@odata.id"] = boost::urls::format("/redfish/v1/JsonSchemas/{}",
+ schema);
members.emplace_back(std::move(member));
}
json["Members"] = std::move(members);
@@ -110,8 +112,8 @@
}
nlohmann::json& json = asyncResp->res.jsonValue;
- json["@odata.id"] = crow::utility::urlFromPieces("redfish", "v1",
- "JsonSchemas", schema);
+ json["@odata.id"] = boost::urls::format("/redfish/v1/JsonSchemas/{}",
+ schema);
json["@odata.type"] = "#JsonSchemaFile.v1_0_2.JsonSchemaFile";
json["Name"] = schema + " Schema File";
json["Description"] = schema + " Schema File Location";
@@ -130,8 +132,8 @@
locationEntry["Language"] = "en";
locationEntry["PublicationUri"] = "http://redfish.dmtf.org/schemas/v1/" +
schema + ".json";
- locationEntry["Uri"] = crow::utility::urlFromPieces(
- "redfish", "v1", "JsonSchemas", schema, std::string(schema) + ".json");
+ locationEntry["Uri"] = boost::urls::format(
+ "/redfish/v1/JsonSchemas/{}/{}", schema, std::string(schema) + ".json");
locationArray.emplace_back(locationEntry);