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(
18 const Value& json,
const utils::TrivialSet<BuilderFunc>& names_to_exclude) {
21 for (
const auto& [name, value] : formats::
common::Items(json)) {
22 if (names_to_exclude.Contains(name))
continue;
24 builder[name] = value;
26 return builder.ExtractValue();
29template <
typename BuilderFunc,
typename Value>
30void ValidateNoAdditionalProperties(
31 const Value& json,
const utils::TrivialSet<BuilderFunc>& names_to_exclude) {
32 for (
const auto& [name, value] : formats::
common::Items(json)) {
33 if (names_to_exclude.Contains(name))
continue;
35 throw std::runtime_error(fmt::format(
"Unknown property '{}'", name));
39template <
typename T,
template <
typename...>
typename Map,
typename Value,
41Map<std::string, formats::common::ParseType<Value, T>>
42ExtractAdditionalProperties(
43 const Value& json,
const utils::TrivialSet<BuilderFunc>& names_to_exclude) {
44 Map<std::string, formats::common::ParseType<Value, T>> map;
46 for (
const auto& [name, value] : formats::
common::Items(json)) {
47 if (names_to_exclude.Contains(name))
continue;
49 map.emplace(name, value.
template As<T>());