userver: yaml_config Namespace Reference
Loading...
Searching...
No Matches
yaml_config Namespace Reference

Detailed Description

YAML-backed static configuration (YamlConfig) and schemas.

Utilities to work with static YAML config.

Classes

class  Iterator
 Forward iterator adapter over YAML-backed configuration containers. More...
struct  PathSupplementary
struct  Schema
 JSON Schema-like type definition. More...
class  SchemaPtr
class  YamlConfig
 Datatype that represents YAML with substituted variables. More...

Typedefs

using Value = YamlConfig
using Exception = formats::yaml::Exception
using ParseException = formats::yaml::ParseException

Enumerations

enum class  FieldType {
  kBool ,
  kInteger ,
  kNumber ,
  kString ,
  kArray ,
  kObject
}

Functions

template<typename ParentComponent>
Schema MergeSchemas (const std::string &yaml_string)
 Merge parent and child components schemas of static configs.
template<typename ParentComponent>
Schema MergeSchemasFromResource (std::string_view resource_name)
template<typename T, typename Value>
std::vector< T > ParseMapToArray (const Value &value)
 Parses YAML object maps into vectors of named elements.
std::string ToString (FieldType type)
formats::yaml::Value Serialize (const SchemaPtr &schema, formats::serialize::To< formats::yaml::Value >)
Schema Parse (const formats::yaml::Value &schema, formats::parse::To< Schema >)
formats::yaml::Value Serialize (const Schema &schema, formats::serialize::To< formats::yaml::Value >)
bool Parse (const YamlConfig &value, formats::parse::To< bool >)
int64_t Parse (const YamlConfig &value, formats::parse::To< int64_t >)
uint64_t Parse (const YamlConfig &value, formats::parse::To< uint64_t >)
double Parse (const YamlConfig &value, formats::parse::To< double >)
std::string Parse (const YamlConfig &value, formats::parse::To< std::string >)
std::chrono::seconds Parse (const YamlConfig &value, formats::parse::To< std::chrono::seconds >)
 Parses duration from string, understands suffixes: ms, s, m, h, d.
std::chrono::milliseconds Parse (const YamlConfig &value, formats::parse::To< std::chrono::milliseconds >)
 Parses duration from string, understands suffixes: ms, s, m, h, d.
formats::json::Value Parse (const YamlConfig &value, formats::parse::To< formats::json::Value >)
 Converts YAML to JSON.
YamlConfig Parse (const YamlConfig &value, formats::parse::To< YamlConfig >)
 Converts YAML to YAML. Returns self.
formats::yaml::Value Parse (const YamlConfig &value, formats::parse::To< formats::yaml::Value >)
 Flattens a YamlConfig, applying all of its special syntax.
template<typename Value>
ItemsWrapper< Value > Items (Value &&value)
 Wrapper for handy python-like iteration over a map.

Typedef Documentation

◆ Exception

using yaml_config::Exception = formats::yaml::Exception

Definition at line 24 of file yaml_config.hpp.

◆ ParseException

using yaml_config::ParseException = formats::yaml::ParseException

Definition at line 25 of file yaml_config.hpp.

◆ Value

using yaml_config::Value = YamlConfig

Definition at line 16 of file fwd.hpp.

Enumeration Type Documentation

◆ FieldType

enum class yaml_config::FieldType
strong

Definition at line 23 of file schema.hpp.

Function Documentation

◆ Items()

template<typename Value>
ItemsWrapper< Value > formats::common::Items ( Value && value)

Wrapper for handy python-like iteration over a map.

for (const auto& [name, value] : Items(map)) {
EXPECT_EQ(name, "key");
EXPECT_EQ(value.As<std::string>(), "value");
break;
}

Definition at line 113 of file items.hpp.

◆ MergeSchemas()

◆ MergeSchemasFromResource()

template<typename ParentComponent>
Schema yaml_config::MergeSchemasFromResource ( std::string_view resource_name)

Definition at line 30 of file merge_schemas.hpp.

◆ Parse() [1/5]

formats::json::Value yaml_config::Parse ( const YamlConfig & value,
formats::parse::To< formats::json::Value >  )

Converts YAML to JSON.

Exceptions
yaml_config::YamlConfig::Exceptionif value.IsMissing()

◆ Parse() [2/5]

formats::yaml::Value yaml_config::Parse ( const YamlConfig & value,
formats::parse::To< formats::yaml::Value >  )

Flattens a YamlConfig, applying all of its special syntax.

Exceptions
yaml_config::YamlConfig::Exceptionif value.IsMissing()

◆ Parse() [3/5]

std::chrono::milliseconds yaml_config::Parse ( const YamlConfig & value,
formats::parse::To< std::chrono::milliseconds >  )

Parses duration from string, understands suffixes: ms, s, m, h, d.

Exceptions
Oninvalid type and invalid string format

◆ Parse() [4/5]

std::chrono::seconds yaml_config::Parse ( const YamlConfig & value,
formats::parse::To< std::chrono::seconds >  )

Parses duration from string, understands suffixes: ms, s, m, h, d.

Exceptions
Oninvalid type, invalid string format, and if the duration is not a whole amount of seconds

◆ Parse() [5/5]

YamlConfig yaml_config::Parse ( const YamlConfig & value,
formats::parse::To< YamlConfig >  )
inline

Converts YAML to YAML. Returns self.

Definition at line 278 of file yaml_config.hpp.

◆ ParseMapToArray()

template<typename T, typename Value>
std::vector< T > yaml_config::ParseMapToArray ( const Value & value)

Parses YAML object maps into vectors of named elements.

Definition at line 16 of file map_to_array.hpp.