userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
static_config_validator.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <
userver/components/component_config.hpp
>
7
#include <
userver/components/raw_component_base.hpp
>
8
#include <userver/yaml_config/impl/validate_static_config.hpp>
9
#include <
userver/yaml_config/schema.hpp
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
components
{
14
15
enum class
ValidationMode {
16
kOnlyTurnedOn,
17
kAll,
18
};
19
20
ValidationMode Parse(
const
yaml_config::YamlConfig& value, formats::parse::To<ValidationMode>);
21
22
namespace
impl {
23
24
[[noreturn]]
void
WrapInvalidStaticConfigSchemaException(
const
std::exception&);
25
26
template
<
typename
Component>
27
void
TryValidateStaticConfig(
28
std::string_view component_name,
29
const
components::ComponentConfig& static_config,
30
ValidationMode validation_condition
31
) {
32
if
(
components::kForceNoValidation<Component>
) {
33
return
;
34
}
35
36
if
(
components::kHasValidate<Component>
|| validation_condition == ValidationMode::kAll) {
37
yaml_config::Schema schema;
38
try
{
39
schema = Component::GetStaticConfigSchema();
40
}
catch
(
const
std::exception& ex) {
41
WrapInvalidStaticConfigSchemaException(ex);
42
}
43
schema.path = component_name;
44
45
yaml_config::impl::Validate(static_config, schema);
46
}
47
}
48
49
template
<
typename
Component>
50
yaml_config::Schema GetStaticConfigSchema() {
51
// TODO: implement for kOnlyTurnedOn
52
return
Component::GetStaticConfigSchema();
53
}
54
55
}
// namespace impl
56
}
// namespace components
57
58
USERVER_NAMESPACE_END
userver
components
static_config_validator.hpp
Generated on
for userver by
Doxygen
1.17.0