| 123456789101112131415161718192021222324252627282930313233343536 |
- #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.
- //
- // Write-time materialisation is permanent: once a workflow is saved with a
- // default baked into its stored config, that key now counts as "present",
- // so a later change to the schema's default will never reach that already-
- // saved workflow - the read path correctly leaves a present key alone. This
- // is an accepted consequence of applying defaults at write time, not a bug;
- // it only affects workflows saved after write-time materialisation shipped,
- // since a workflow saved before that never had the key baked in to begin
- // with, and still picks up schema default changes at read time.
- nlohmann::json applyConfigDefaults(const nlohmann::json& config,
- const nlohmann::json& config_schema);
- } // namespace smartbotic::common
|