Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #419 #422

Merged
merged 1 commit into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
(defn -parse-entries [children {:keys [naked-keys lazy-refs]} options]
(let [-parse (fn [e] (let [[[k ?p ?v] f] (cond
(-reference? e) (if naked-keys [[e nil e] e])
(and (= 1 (count e)) (-reference? (first e))) (if naked-keys [[(first e) nil (first e)] e])
(and (= 2 (count e)) (-reference? (first e)) (map? (last e))) (if naked-keys [(conj e (first e)) e])
:else [e (->> (-update (vec e) (dec (count e)) (-comp -form #(schema % options))) (keep identity) (vec))])
[p ?s] (if (or (nil? ?p) (map? ?p)) [?p ?v] [nil ?p])
Expand Down
6 changes: 4 additions & 2 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1754,16 +1754,18 @@

(deftest custom-registry-qualified-keyword-in-map-test
(let [schema [:map {:registry {::id int?
::location [:tuple :int :int]
::country string?}}
::id
[::location]
[:name string?]
[::country {:optional true}]]]

(testing "Example with qualified keyword + optional, regular key"
(is (m/validate schema {::id 123 ::country "Finland" :name "Malli"})))
(is (m/validate schema {::id 123 ::location [1 1] ::country "Finland" :name "Malli"})))

(testing "Optional qualified keyword is optional"
(is (m/validate schema {::id 123 :name "Malli"})))))
(is (m/validate schema {::id 123 ::location [1 1] :name "Malli"})))))

(deftest simple-schemas
(testing "simple schemas"
Expand Down