userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
schema.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <memory>
7
#include <optional>
8
#include <string>
9
#include <string_view>
10
#include <unordered_map>
11
#include <unordered_set>
12
#include <variant>
13
#include <vector>
14
15
#include <
userver/formats/yaml_fwd.hpp
>
16
17
USERVER_NAMESPACE_BEGIN
18
19
namespace
yaml_config
{
20
21
struct
Schema
;
22
23
enum class
FieldType {
24
kBool,
25
kInteger,
26
kNumber,
27
kString,
28
kArray,
29
kObject,
30
};
31
32
std::string ToString(FieldType type);
33
34
class
SchemaPtr final {
35
public
:
36
explicit
SchemaPtr(
Schema
&& schema);
37
38
SchemaPtr(SchemaPtr&&)
noexcept
=
default
;
39
SchemaPtr& operator=(SchemaPtr&&)
noexcept
=
default
;
40
SchemaPtr(
const
SchemaPtr&);
41
SchemaPtr& operator=(
const
SchemaPtr&);
42
43
const
Schema
& operator*()
const
;
44
Schema
& operator*();
45
const
Schema
* operator->()
const
{
return
&**
this
; }
46
Schema
* operator->() {
return
&**
this
; }
47
48
bool
operator==(
const
SchemaPtr&)
const
;
49
50
private
:
51
std::unique_ptr<Schema> schema_;
52
};
53
54
formats::yaml::Value
Serialize(
const
SchemaPtr
& schema,
formats::serialize::To<formats::yaml::Value>
);
55
58
struct
PathSupplementary
{
59
bool
operator==(
const
PathSupplementary
&)
const
noexcept
;
60
61
std::string path;
62
};
63
70
struct
Schema
final :
public
PathSupplementary
{
71
void
UpdateDescription(std::string new_description);
72
73
static
Schema
EmptyObject();
74
75
bool
operator==(
const
Schema
&)
const
noexcept
;
76
77
FieldType type{};
78
std::string description;
79
std::optional<std::string> default_description;
80
std::optional<std::variant<bool, SchemaPtr>> additional_properties;
81
std::optional<std::unordered_map<std::string, SchemaPtr>> properties;
82
std::optional<SchemaPtr> items;
83
std::optional<std::unordered_set<std::string>> enum_values;
84
std::optional<double> minimum;
85
std::optional<double> maximum;
86
std::optional<std::size_t> min_items;
87
std::optional<std::size_t> max_items;
88
std::optional<std::unordered_set<std::string>> required;
89
};
90
91
Schema
Parse(
const
formats::yaml::Value
& schema,
formats::parse::To<Schema>
);
92
93
formats::yaml::Value
Serialize(
const
Schema
& schema,
formats::serialize::To<formats::yaml::Value>
);
94
95
namespace
impl {
96
97
Schema
SchemaFromString(
const
std::string& yaml_string);
98
Schema
SchemaFromResource(std::string_view resource_name);
99
100
}
// namespace impl
101
102
}
// namespace yaml_config
103
104
USERVER_NAMESPACE_END
userver
yaml_config
schema.hpp
Generated on
for userver by
Doxygen
1.17.0