| 123456789101112131415161718192021222324252627 |
- #pragma once
- #include <nlohmann/json.hpp>
- namespace smartbotic::common {
- // Applies configSchema-declared defaults to a node config.
- //
- // Returns a copy of `config` with any property from
- // `config_schema["properties"]` that declares a "default" filled in, but
- // only when `config` does not already contain that key. A key that is
- // present - even with a falsy value like false, 0, null, or "" - is a
- // deliberate, stored value and is never overwritten.
- //
- // Scope limit (by design, not an oversight): only top-level properties are
- // considered. Defaults nested inside object properties or array item
- // schemas are NOT applied. Nodes are not currently written with nested
- // config shapes that rely on defaults, so recursing was left out to keep
- // this function's behaviour easy to reason about; revisit if that changes.
- //
- // Tolerant of a missing/null/non-object schema, or one with no
- // "properties" - in all of those cases the config is returned unchanged
- // rather than throwing.
- nlohmann::json applyConfigDefaults(const nlohmann::json& config,
- const nlohmann::json& config_schema);
- } // namespace smartbotic::common
|