Skip to content

Commit

Permalink
Merge pull request #423 from metosin/fix-parsing-ref
Browse files Browse the repository at this point in the history
fix #418
  • Loading branch information
ikitommi authored Apr 24, 2021
2 parents ddb9e97 + dd965bd commit bd7a4bb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Malli is in [alpha](README.md#alpha).

* Add `ifn?` predicate, [#416](https://github.com/metosin/malli/pull/416)
* Accumulate errors correctly with `m/-explain` with `:function` and `:=>` Schemas
* Fix [#419](https://github.com/metosin/malli/issues/419): Parsing bug in :map schema
* Fix [#418](https://github.com/metosin/malli/issues/418): Better error messages / docs for registry references

### Extender API

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Maps keys are not limited to keywords:

## Qualified keys in a map

You can also use [decomplected maps keys and values](https://clojure.org/about/spec#_decomplect_mapskeysvalues) using registry references.
You can also use [decomplected maps keys and values](https://clojure.org/about/spec#_decomplect_mapskeysvalues) using registry references. References must be either qualified keywords of strings.

```clj
(m/validate
Expand Down
2 changes: 1 addition & 1 deletion src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,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])
(not (sequential? e)) (if (and naked-keys (-reference? e)) [[e nil e] e] (miu/-fail! ::invalid-ref {:ref 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))])
Expand Down
7 changes: 6 additions & 1 deletion test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,12 @@
(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 ::location [1 1] :name "Malli"})))))
(is (m/validate schema {::id 123 ::location [1 1] :name "Malli"}))))

(testing "invalid ref"
(is (thrown-with-msg?
#?(:clj Exception, :cljs js/Error) #":malli.core/invalid-ref"
(m/schema [:map {:registry {:kikka :int}} :int])))))

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

0 comments on commit bd7a4bb

Please sign in to comment.