ocpp 0.24.1
A C++ implementation of the Open Charge Point Protocol
schemas.hpp
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
3#ifndef OCPP_COMMON_SCHEMAS_HPP
4#define OCPP_COMMON_SCHEMAS_HPP
5
6#include <map>
7#include <regex>
8#include <set>
9#include <vector>
10
11#include <everest/logging.hpp>
12#include <nlohmann/json-schema.hpp>
13#include <nlohmann/json_fwd.hpp>
14#include <ocpp/common/support_older_cpp_versions.hpp>
15
16using json = nlohmann::json;
17using json_uri = nlohmann::json_uri;
18using json_validator = nlohmann::json_schema::json_validator;
19
20namespace ocpp {
21
23class Schemas {
24private:
25 json schema;
26 std::shared_ptr<json_validator> validator;
27 fs::path schemas_path;
28 std::set<fs::path> available_schemas_paths;
29 const static std::vector<std::string> profiles;
30 const static std::regex date_time_regex;
31
33 void load_root_schema();
34
36 void loader(const json_uri& uri, json& schema);
37
38public:
40 explicit Schemas(fs::path schemas_path);
42 explicit Schemas(const json& schema_in);
44 explicit Schemas(json&& schema_in);
45
48 json get_schema();
49
52 std::shared_ptr<json_validator> get_validator();
53
55 static void format_checker(const std::string& format, const std::string& value);
56};
57} // namespace ocpp
58
59#endif // OCPP_COMMON_SCHEMAS_HPP
Contains the json schema validation for the libocpp config.
Definition: schemas.hpp:23
Schemas(fs::path schemas_path)
Creates a new Schemas object looking for the root schema file in relation to the provided main_dir.
Definition: schemas.cpp:12
static void format_checker(const std::string &format, const std::string &value)
Provides a format checker for the given format and value.
Definition: schemas.cpp:85
json get_schema()
Provides the config schema.
Definition: schemas.cpp:56
std::shared_ptr< json_validator > get_validator()
Provides the config schema validator.
Definition: schemas.cpp:60