summaryrefslogtreecommitdiff
path: root/redfish-core/lib/odata.hpp
blob: 5aa62f225c7683599896d3b6a5236218d6c4d4f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors
#pragma once

#include "app.hpp"
#include "async_resp.hpp"
#include "http_request.hpp"
#include "http_response.hpp"

#include <boost/beast/http/verb.hpp>
#include <boost/url/format.hpp>
#include <boost/url/url.hpp>
#include <nlohmann/json.hpp>

#include <memory>
#include <ranges>
#include <string>
#include <string_view>
#include <utility>

namespace redfish
{

inline void redfishOdataGet(const crow::Request& /*req*/,
                            const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
{
    nlohmann::json::object_t obj;
    obj["@odata.context"] = "/redfish/v1/$metadata";
    nlohmann::json::array_t value;
    for (std::string_view service :
         {"$metadata", "odata", "JsonSchemas", "Service", "ServiceRoot",
          "Systems", "Chassis", "Managers", "SessionService", "AccountService",
          "UpdateService"})
    {
        nlohmann::json::object_t serviceObj;
        serviceObj["kind"] = "Singleton";
        serviceObj["name"] = "$metadata";
        boost::urls::url url = boost::urls::format("/redfish/v1/{}", service);
        if (service == "Service")
        {
            url = boost::urls::url("/redfish/v1");
        }
        serviceObj["url"] = url;
        value.emplace_back(std::move(serviceObj));
    }

    obj["value"] = std::move(value);

    asyncResp->res.jsonValue = std::move(obj);
}

inline void requestRoutesOdata(App& app)
{
    BMCWEB_ROUTE(app, "/redfish/v1/odata/")
        .methods(boost::beast::http::verb::get)(redfishOdataGet);
}

} // namespace redfish