mt/strip-extra-keys-transformer fails on :and and :or schemas #657
Unanswered
kyleerhabor
asked this question in
Q&A
Replies: 1 comment
-
I was able to partially solve my problem: (defn mapj-marker [type]
(if (= :and type)
identity ; No need to make the keys required. Gives the caller more freedom.
mu/optional-keys))
(defn mapj [schema]
(let [type (m/type schema)
entries (m/children schema)]
(if (and (#{:and :or} type) (every? (comp (partial = :map) m/type) entries))
(let [mark (mapj-marker type)]
(reduce #(mu/merge (mark %1) (mark %2)) :map entries))
schema)))
(defn walk-mapj [schema]
(m/walk schema (m/schema-walker mapj)))
(def S [:and
[:map [:media/title :string] [:media/description :string]]
[:or [:map [:film/likable? :boolean]] [:map [:book/likable? :boolean]]]])
(walk-mapj S)
;; [:map
;; [:media/title :string]
;; [:media/description :string]
;; [:film/likable? {:optional true} :boolean]
;; [:book/likable? {:optional true} :boolean]] For my problem domain, I need to make sure only one of the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello, I'm trying to use a transformation to format a request map. Say I have a map like this:
For most requests, I'm able to use this function to minimize the map:
When I apply it to the request map above, I'd expect the following result:
However, it doesn't return that. Instead, it results in this:
In my problem domain, a
Media
is a base structure with other structures building on top of it, such as aFilm
orBook
(as seen in the schema). Since there's currently no support for relations, I've made use of:and
and:or
, but it seems that the transformation only cares about the first map schema (so nothing in the:or
). Is there any way I could get around this?Beta Was this translation helpful? Give feedback.
All reactions