| 123456789101112131415161718192021222324252627282930313233343536373839 |
- #include "common/config_defaults.hpp"
- namespace smartbotic::common {
- nlohmann::json applyConfigDefaults(const nlohmann::json& config,
- const nlohmann::json& config_schema) {
- nlohmann::json result = config.is_object() ? config : nlohmann::json::object();
- if (!config_schema.is_object()) {
- return result;
- }
- auto properties_it = config_schema.find("properties");
- if (properties_it == config_schema.end() || !properties_it->is_object()) {
- return result;
- }
- for (auto it = properties_it->begin(); it != properties_it->end(); ++it) {
- const std::string& key = it.key();
- const nlohmann::json& property_schema = it.value();
- if (!property_schema.is_object()) {
- continue;
- }
- auto default_it = property_schema.find("default");
- if (default_it == property_schema.end()) {
- continue;
- }
- if (!result.contains(key)) {
- result[key] = *default_it;
- }
- }
- return result;
- }
- } // namespace smartbotic::common
|