diff --git a/src/active/data/realm/schema.cljc b/src/active/data/realm/schema.cljc index a3d5d84..4b7eed1 100644 --- a/src/active/data/realm/schema.cljc +++ b/src/active/data/realm/schema.cljc @@ -131,8 +131,9 @@ (into {} (map (fn [[key realm]] (if (realm-inspection/optional? realm) + ;; make both keys and value optional - (:key {}) == (:key {:key nil}) [(schema/optional-key key) - (schema (realm-inspection/optional-realm-realm realm))] + (schema realm)] [(schema/required-key key) (schema realm)])) (realm-inspection/map-with-keys-realm-map realm))) diff --git a/test/active/data/realm/validation_test.cljc b/test/active/data/realm/validation_test.cljc index e1a2de3..df6e29a 100644 --- a/test/active/data/realm/validation_test.cljc +++ b/test/active/data/realm/validation_test.cljc @@ -15,3 +15,10 @@ (realm-validation/checking (twoify "7"))))) +(deftest key-value-optional-test + ;; optional value realm results in both optional value and optional key schema + (let [map-realm (realm/map-with-keys {:key (realm/optional realm/string)}) + check (realm-validation/validator map-realm)] + (is (= {:key nil} (check {:key nil}))) + (is (= {} (check {}))) + (is (= {:key "foo"} (check {:key "foo"})))))