mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
Use namespace alias to refer Record types in schema coercion ns
Since Cljs 1.10.439 using qualified name hasn't worked to refer to record types.
This commit is contained in:
parent
acfc48faa1
commit
e7a480366f
2 changed files with 21 additions and 4 deletions
|
|
@ -26,11 +26,11 @@
|
||||||
(fn [x]
|
(fn [x]
|
||||||
(cond
|
(cond
|
||||||
#?@(:clj [(class? x) (.getName ^Class x)])
|
#?@(:clj [(class? x) (.getName ^Class x)])
|
||||||
(instance? schema.core.OptionalKey x) (pr-str (list 'opt (:k x)))
|
(instance? #?(:clj schema.core.OptionalKey :cljs s/OptionalKey) x) (pr-str (list 'opt (:k x)))
|
||||||
(instance? schema.core.RequiredKey x) (pr-str (list 'req (:k x)))
|
(instance? #?(:clj schema.core.RequiredKey :cljs s/RequiredKey) x) (pr-str (list 'req (:k x)))
|
||||||
(and (satisfies? s/Schema x) (record? x)) (try (pr-str (s/explain x)) (catch #?(:clj Exception :cljs js/Error) _ x))
|
(and (satisfies? s/Schema x) (record? x)) (try (pr-str (s/explain x)) (catch #?(:clj Exception :cljs js/Error) _ x))
|
||||||
(instance? schema.utils.ValidationError x) (str (su/validation-error-explain x))
|
(instance? #?(:clj schema.utils.ValidationError :cljs su/ValidationError) x) (str (su/validation-error-explain x))
|
||||||
(instance? schema.utils.NamedError x) (str (su/named-error-explain x))
|
(instance? #?(:clj schema.utils.NamedError :cljs su/NamedError) x) (str (su/named-error-explain x))
|
||||||
:else x))
|
:else x))
|
||||||
schema))
|
schema))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
[reitit.coercion.spec]
|
[reitit.coercion.spec]
|
||||||
[reitit.core :as r]
|
[reitit.core :as r]
|
||||||
[schema.core :as s]
|
[schema.core :as s]
|
||||||
|
[schema.utils :as su]
|
||||||
[spec-tools.data-spec :as ds])
|
[spec-tools.data-spec :as ds])
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(:import (clojure.lang ExceptionInfo))))
|
(:import (clojure.lang ExceptionInfo))))
|
||||||
|
|
@ -106,3 +107,19 @@
|
||||||
{:compile coercion/compile-request-coercers})]
|
{:compile coercion/compile-request-coercers})]
|
||||||
(is (= {:path {:user-id 123, :company "metosin"}}
|
(is (= {:path {:user-id 123, :company "metosin"}}
|
||||||
(:parameters (match-by-path-and-coerce! router "/metosin/users/123"))))))
|
(:parameters (match-by-path-and-coerce! router "/metosin/users/123"))))))
|
||||||
|
|
||||||
|
(deftest schema-stringify-test
|
||||||
|
(is (= {"(opt :foo)" #?(:clj "java.lang.String" :cljs "Str")
|
||||||
|
"(req \"bar\")" #?(:clj "java.lang.String" :cljs "Str")}
|
||||||
|
(reitit.coercion.schema/stringify
|
||||||
|
{(s/optional-key :foo) s/Str
|
||||||
|
(s/required-key "bar") s/Str})))
|
||||||
|
|
||||||
|
(is (= "(named \"error-object\" \"name\")"
|
||||||
|
(reitit.coercion.schema/stringify
|
||||||
|
(new #?(:clj schema.utils.NamedError :cljs su/NamedError) "name" "error-object"))))
|
||||||
|
|
||||||
|
(is (= "(not :foo)"
|
||||||
|
(reitit.coercion.schema/stringify
|
||||||
|
(new #?(:clj schema.utils.ValidationError :cljs su/ValidationError)
|
||||||
|
nil nil (delay :foo) nil)))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue