🐛 Fix path content json decoding mechanism

This commit is contained in:
Andrey Antukh 2025-04-23 16:12:11 +02:00
parent 1981946480
commit 122e5a4b57

View file

@ -586,9 +586,6 @@
(def ^:private check-segments (def ^:private check-segments
(sm/check-fn schema:segments)) (sm/check-fn schema:segments))
(sm/register! ::path/segment schema:segment)
(sm/register! ::path/segments schema:segments)
(defn path-data? (defn path-data?
[o] [o]
(instance? PathData o)) (instance? PathData o))
@ -596,24 +593,34 @@
(declare from-string) (declare from-string)
(declare from-plain) (declare from-plain)
;; Mainly used on backend: features/components_v2.clj
(sm/register! ::path/segment schema:segment)
(sm/register! ::path/segments schema:segments)
(sm/register! (sm/register!
{:type ::path/content {:type ::path/content
:pred path-data? :compile
:type-properties (fn [_ _ _]
{:gen/gen (->> (sg/generator schema:segments) (let [decoder (delay (sm/decoder schema:segments sm/json-transformer))
(sg/filter not-empty) generator (->> (sg/generator schema:segments)
(sg/fmap #(from-plain %))) (sg/filter not-empty)
:encode/json identity (sg/fmap from-plain))]
:decode/json (fn [s] {:pred path-data?
(cond :type-properties
(string? s) {:gen/gen generator
(from-string s) :encode/json identity
:decode/json (fn [s]
(cond
(string? s)
(from-string s)
(vector? s) (vector? s)
(from-plain s) (let [decode-fn (deref decoder)]
(-> (decode-fn s)
(from-plain)))
:else :else
s))}}) s))}}))})
(def check-path-content (def check-path-content
(sm/check-fn ::path/content)) (sm/check-fn ::path/content))