14 #include "eckit/exception/Exceptions.h"
15 #include "eckit/utils/StringTools.h"
16 #include "oops/util/CompositePath.h"
17 #include "oops/util/LocalEnvironment.h"
18 #include "oops/util/parameters/ParameterTraits.h"
19 #include "oops/util/stringFunctions.h"
25 util::CompositePath &path,
const eckit::Configuration &config,
const std::string& name) {
26 if (config.has(name)) {
27 std::list<std::string> messages;
33 util::LocalEnvironment localEnv;
34 localEnv.set(
"ECKIT_EXCEPTION_IS_SILENT",
"1");
44 eckit::LocalConfiguration varConf(config, name);
46 }
catch (eckit::Exception &e) {
48 messages.emplace_back(e.what());
56 std::string varAndGroup = config.getString(name);
58 }
catch (eckit::Exception &e) {
60 messages.emplace_back(e.what());
67 messages.push_front(
"The key '" + name +
68 "' is set to neither a string nor a map with the correct keys.");
69 throw eckit::Exception(eckit::StringTools::join(
"\n", messages.begin(), messages.end()),
77 const std::string &name,
79 eckit::LocalConfiguration subConfig;
80 subConfig.set(
"name", value.
variable() +
"@" + value.
group());
81 const std::vector<int> &channels = value.
channels();
82 if (!channels.empty()) {
83 const std::string channelsAsString = util::stringfunctions::join(
84 ",", channels.begin(), channels.end(), [](
int n) { return std::to_string(n); });
85 subConfig.set(
"channels", channelsAsString);
87 if (!value.
options().keys().empty())
88 subConfig.set(
"options", value.
options());
89 config.set(name, subConfig);
93 std::stringstream oneOf;
99 eckit::AutoIndent indent(ch);
100 ObjectJsonSchema simpleSchema = ParameterTraits<std::string>::jsonSchema(
"");
101 ObjectJsonSchema completeSchema({{
"name", {{
"type",
"\"string\""}}},
102 {
"options", {{
"type",
"\"object\""}}},
103 {
"channels", {{
"type",
"[\"string\", \"integer\"]"}}}});
104 ch << toString(simpleSchema.properties().at(
"")) <<
",\n";
105 ch << completeSchema.toString() <<
'\n';
110 return ObjectJsonSchema({{name, {{
"oneOf", oneOf.str()}}}});
const std::string & variable() const
const std::string & group() const
const eckit::LocalConfiguration & options() const
const std::vector< int > & channels() const
static boost::optional< ufo::Variable > get(util::CompositePath &path, const eckit::Configuration &config, const std::string &name)
static void set(eckit::LocalConfiguration &config, const std::string &name, const ufo::Variable &value)
static ObjectJsonSchema jsonSchema(const std::string &name)