1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #pragma once 4 5 #include "app.hpp" 6 #include "error_messages.hpp" 7 #include "http_request.hpp" 8 #include "http_response.hpp" 9 #include "query.hpp" 10 #include "registries/privilege_registry.hpp" 11 #include "utility.hpp" 12 13 #include <boost/url/format.hpp> 14 #include <nlohmann/json.hpp> 15 16 #include <memory> 17 #include <ranges> 18 #include <string> 19 #include <string_view> 20 21 namespace redfish 22 { 23 24 inline void redfishOdataGet(const crow::Request& /*req*/, 25 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 26 { 27 nlohmann::json::object_t obj; 28 obj["@odata.context"] = "/redfish/v1/$metadata"; 29 nlohmann::json::array_t value; 30 for (std::string_view service : 31 {"$metadata", "odata", "JsonSchemas", "Service", "ServiceRoot", 32 "Systems", "Chassis", "Managers", "SessionService", "AccountService", 33 "UpdateService"}) 34 { 35 nlohmann::json::object_t serviceObj; 36 serviceObj["kind"] = "Singleton"; 37 serviceObj["name"] = "$metadata"; 38 boost::urls::url url = boost::urls::format("/redfish/v1/{}", service); 39 if (service == "Service") 40 { 41 url = boost::urls::url("/redfish/v1"); 42 } 43 serviceObj["url"] = url; 44 value.emplace_back(std::move(serviceObj)); 45 } 46 47 obj["value"] = std::move(value); 48 49 asyncResp->res.jsonValue = std::move(obj); 50 } 51 52 inline void requestRoutesOdata(App& app) 53 { 54 BMCWEB_ROUTE(app, "/redfish/v1/odata/") 55 .methods(boost::beast::http::verb::get)(redfishOdataGet); 56 } 57 58 } // namespace redfish 59