Skip to content

Commit

Permalink
look up to one registry level for IntoSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Jul 17, 2024
1 parent 11b6e22 commit 8eadc26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/malli/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,11 @@
(-fail! ::invalid-schema {:schema ?schema, :form ?form}))))

(defn- -lookup-into-schema [?schema options]
(let [registry (-registry options)]
(loop [?schema ?schema]
(if (into-schema? ?schema)
?schema
(some-> (mr/-schema registry ?schema)
recur)))))
(if (into-schema? ?schema)
?schema
(let [?schema (mr/-schema (-registry options) ?schema)]
(when (into-schema? ?schema)
?schema))))

(defn -properties-and-options [properties options f]
(if-let [r (:registry properties)]
Expand Down Expand Up @@ -1693,7 +1692,7 @@
(let [children (-vmap #(schema % options) children)
child (nth children 0)
form (delay (let [no-props? (empty? properties)]
(or (if id
(or (when id
(if no-props?
id
[id properties]))
Expand Down
11 changes: 11 additions & 0 deletions test/malli/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -3379,9 +3379,20 @@
(is (m/schema ::string options))
(is (m/schema [::string] options))
(is (m/schema [::string {:foo :bar}] options))
(is (m/schema [::string {:foo :bar}] options))
(is (validate ::string "a"))
(is (not (validate ::string 1)))
(is (validate [:schema {:registry {::string :int}} ::string] 1))
(is (= [:schema {:registry {::string :int}} ::string]
(-> [:schema {:registry {::string :int}} ::string]
(m/form options))))
(is (validate [:schema {:registry {::string :int}} [::string {:foo :bar}]] 1))
(is (= [:schema {:registry {::string :int}} [::string {:foo :bar}]]
(-> [:schema {:registry {::string :int}} [::string {:foo :bar}]]
(m/form options))))
(is (= [:schema {:registry {::string [:tuple :int]}} [::string {:foo :bar}]]
(-> [:schema {:registry {::string [:tuple :int]}} [::string {:foo :bar}]]
(m/form options))))
(is (not (validate [:schema {:registry {::string :int}} [::string]] "a")))
(is (not (validate [:schema {:registry {::string :int}} [::string {:foo :bar}]] "a")))))

Expand Down

0 comments on commit 8eadc26

Please sign in to comment.