userver: userver/components/static_config_validator.hpp Source File
Loading...
Searching...
No Matches
static_config_validator.hpp
1#pragma once
2
3#include <userver/components/component_config.hpp>
4#include <userver/components/raw_component_base.hpp>
5#include <userver/yaml_config/impl/validate_static_config.hpp>
6#include <userver/yaml_config/schema.hpp>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace components {
11
12enum class ValidationMode {
13 kOnlyTurnedOn,
14 kAll,
15};
16
17ValidationMode Parse(const yaml_config::YamlConfig& value, formats::parse::To<ValidationMode>);
18
19namespace impl {
20template <typename Component>
21void TryValidateStaticConfig(
22 std::string_view component_name,
23 const components::ComponentConfig& static_config,
24 ValidationMode validation_condition
25) {
26 if (components::kHasValidate<Component> || validation_condition == ValidationMode::kAll) {
27 yaml_config::Schema schema = Component::GetStaticConfigSchema();
28 schema.path = component_name;
29
30 yaml_config::impl::Validate(static_config, schema);
31 }
32}
33
34template <typename Component>
35yaml_config::Schema GetStaticConfigSchema() {
36 // TODO: implement for kOnlyTurnedOn
37 return Component::GetStaticConfigSchema();
38}
39
40} // namespace impl
41} // namespace components
42
43USERVER_NAMESPACE_END