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 <string>
7
#include <string_view>
8
9
#include <
userver/formats/json/exception.hpp
>
10
#include <
userver/formats/json/value.hpp
>
11
#include <
userver/utils/fast_pimpl.hpp
>
12
13
USERVER_NAMESPACE_BEGIN
14
15
namespace
formats::json
{
16
18
class
SchemaValidationException final :
public
ExceptionWithPath {
19
public
:
20
SchemaValidationException(std::string_view msg, std::string_view path, std::string_view schema_path);
21
22
std::string_view GetSchemaPath()
const
noexcept
;
23
24
private
:
25
std::string schema_path_;
26
};
27
32
class
Schema final {
33
public
:
34
class
ValidationResult
;
35
class
ValidationError
;
36
37
explicit
Schema(
const
Value
& doc);
38
~Schema()
noexcept
;
39
42
ValidationResult
Validate
(
const
Value
& doc)
const
;
43
44
private
:
45
struct
Impl;
46
static
constexpr
std::size_t kSize = 288;
47
static
constexpr
std::size_t kAlignment = 8;
48
utils::FastPimpl<Impl, kSize, kAlignment>
impl_;
49
};
50
52
class
Schema::ValidationResult
final {
53
public
:
55
ValidationResult
() noexcept;
56
57
ValidationResult
(
ValidationResult
&&) noexcept;
58
ValidationResult
& operator=(
ValidationResult
&&) noexcept;
59
~
ValidationResult
() noexcept;
60
62
explicit operator
bool
() const noexcept;
63
65
bool
IsValid
() const noexcept;
66
68
bool
IsError
() const noexcept;
69
73
void
ThrowIfError
() &&;
74
76
ValidationError
GetError
() &&;
77
78
private:
79
friend class Schema;
80
friend class ValidationError;
81
82
struct Impl;
83
static constexpr
std
::
size_t
kSize = 24;
84
static constexpr
std
::
size_t
kAlignment = 8;
85
utils
::FastPimpl<Impl, kSize, kAlignment> impl_;
86
};
87
88
class Schema::ValidationError final {
89
public
:
92
[[noreturn]]
void
Throw
()
const
;
93
97
std::string_view
GetValuePath
() const noexcept;
98
101
std
::string_view
GetSchemaPath
() const noexcept;
102
105
std
::string_view
GetDetailsString
() const noexcept;
106
107
private:
108
friend class ValidationResult;
109
110
ValidationError();
111
112
std
::
string
value_path_;
113
std
::
string
schema_path_;
114
std
::
string
details_string_;
115
};
116
117
}
// namespace formats::json
118
119
USERVER_NAMESPACE_END
userver
formats
json
schema.hpp
Generated on
for userver by
Doxygen
1.17.0