1 // SPDX-License-Identifier: Apache-2.0
2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3 #pragma once
4
5 #include "app.hpp"
6 #include "async_resp.hpp"
7 #include "http_request.hpp"
8 #include "http_response.hpp"
9
10 #include <boost/beast/http/verb.hpp>
11 #include <boost/url/format.hpp>
12 #include <boost/url/url.hpp>
13 #include <nlohmann/json.hpp>
14
15 #include <memory>
16 #include <ranges>
17 #include <string>
18 #include <string_view>
19 #include <utility>
20
21 namespace redfish
22 {
23
redfishOdataGet(const crow::Request &,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)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
requestRoutesOdata(App & app)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