Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st/strip-extra-keys-transformer not handling merged s/or #271

Open
kolstae opened this issue Mar 22, 2023 · 0 comments
Open

st/strip-extra-keys-transformer not handling merged s/or #271

kolstae opened this issue Mar 22, 2023 · 0 comments

Comments

@kolstae
Copy link

kolstae commented Mar 22, 2023

Similar to #178 and might be related to #264

When having a spec with merge of an or-spec, st/strip-extra-keys-transformer removes too many keys. However it seems to be an issue with parsing of the specs.

(ns merged-or.test
  (:require [clojure.spec.alpha :as s]
            [spec-tools.core :as st]))

(s/def ::a int?)
(s/def ::doors int?)
(s/def ::wheels int?)
(s/def ::car (s/keys :req-un [::doors]))
(s/def ::bike (s/keys :req-un [::wheels]))
(s/def ::vehicle (s/or :car ::car
                       :bike ::bike))
(s/def ::merged-or (s/merge ::vehicle
                            (s/keys :opt-un [::a])))
(s/def ::merged-or-reversed (s/merge (s/keys :opt-un [::a])
                                     ::vehicle))

(let [chevy {:doors 4 :a 1}]
  [(st/coerce ::merged-or chevy st/json-transformer)
   (st/coerce ::merged-or chevy st/strip-extra-keys-transformer)
   (st/coerce ::merged-or-reversed chevy st/strip-extra-keys-transformer)])
; => [{:doors 4, :a 1}
;     {:a 1}
;     {:doors 4, :a 1}]

I've not been able to create a fix :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant