Skip to content

Commit

Permalink
Merge pull request #152 from miikka/fix-fail-on-extra-keys
Browse files Browse the repository at this point in the history
Make fail-on-extra-keys-transformer work
  • Loading branch information
ikitommi authored Nov 26, 2018
2 parents 30ecf32 + 5117c0f commit 11450cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/spec_tools/transform.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
x))

;; TODO: remove this as it couples transformation & validation?
(defn fail-on-extra-keys [{:keys [keys]} x]
(defn fail-on-extra-keys [{:keys [::parse/keys]} x]
(if (and (map? x) (not (set/subset? (-> x (clojure.core/keys) (set)) keys)))
::s/invalid
x))
Expand Down
3 changes: 3 additions & 0 deletions test/cljc/spec_tools/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@
(st/select-spec ::person-spec person))))

(testing "failing on extra keys"
(is (not (s/invalid? (st/conform ::person
{:height 200, :weight 80}
st/fail-on-extra-keys-transformer))))
(is (s/invalid? (st/conform ::person person st/fail-on-extra-keys-transformer)))
(is (s/invalid? (st/conform ::person-spec person st/fail-on-extra-keys-transformer))))

Expand Down

0 comments on commit 11450cd

Please sign in to comment.