Github   Telegram
Loading...
Searching...
No Matches
static_config_validator.hpp
1#pragma once
2
3#include <userver/components/component_config.hpp>
4#include <userver/components/impl/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,
18 formats::parse::To<ValidationMode>);
19
20namespace impl {
21template <typename Component>
22void TryValidateStaticConfig(const components::ComponentConfig& static_config,
23 ValidationMode validation_condition) {
24 if (components::kHasValidate<Component> ||
25 validation_condition == ValidationMode::kAll) {
26 yaml_config::Schema schema = Component::GetStaticConfigSchema();
27
28 yaml_config::impl::Validate(static_config, schema);
29 }
30}
31
32} // namespace impl
33} // namespace components
34
35USERVER_NAMESPACE_END