4#include <unordered_map>
8#include <userver/formats/common/items.hpp>
9#include <userver/formats/json/value_builder.hpp>
10#include <userver/utils/trivial_map.hpp>
12USERVER_NAMESPACE_BEGIN
16template <
typename BuilderFunc,
typename Value>
17Value ExtractAdditionalPropertiesTrue(
const Value& json,
const utils::TrivialSet<BuilderFunc>& names_to_exclude) {
20 for (
const auto& [name, value] : formats::
common::Items(json)) {
21 if (names_to_exclude.Contains(name))
continue;
23 builder[name] = value;
25 return builder.ExtractValue();
28template <
typename BuilderFunc,
typename Value>
29void ValidateNoAdditionalProperties(
const Value& json,
const utils::TrivialSet<BuilderFunc>& names_to_exclude) {
30 for (
const auto& [name, value] : formats::
common::Items(json)) {
31 if (names_to_exclude.Contains(name))
continue;
33 throw std::runtime_error(fmt::format(
"Unknown property '{}'", name));
37template <
typename T,
template <
typename...>
typename Map,
typename Value,
typename BuilderFunc>
38Map<std::string, formats::common::ParseType<Value, T>>
39ExtractAdditionalProperties(
const Value& json,
const utils::TrivialSet<BuilderFunc>& names_to_exclude) {
40 Map<std::string, formats::common::ParseType<Value, T>> map;
42 for (
const auto& [name, value] : formats::
common::Items(json)) {
43 if (names_to_exclude.Contains(name))
continue;
45 map.emplace(name, value.
template As<T>());