blob: 5aa62f225c7683599896d3b6a5236218d6c4d4f9 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Ed Tanousd5c01722024-06-16 12:10:33 -07003#pragma once
4
5#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08006#include "async_resp.hpp"
Ed Tanousd5c01722024-06-16 12:10:33 -07007#include "http_request.hpp"
8#include "http_response.hpp"
Ed Tanousd5c01722024-06-16 12:10:33 -07009
Ed Tanousd7857202025-01-28 15:32:26 -080010#include <boost/beast/http/verb.hpp>
Ed Tanousd5c01722024-06-16 12:10:33 -070011#include <boost/url/format.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080012#include <boost/url/url.hpp>
Ed Tanousd5c01722024-06-16 12:10:33 -070013#include <nlohmann/json.hpp>
14
15#include <memory>
16#include <ranges>
17#include <string>
18#include <string_view>
Ed Tanousd7857202025-01-28 15:32:26 -080019#include <utility>
Ed Tanousd5c01722024-06-16 12:10:33 -070020
21namespace redfish
22{
23
24inline 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
52inline 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