-
Notifications
You must be signed in to change notification settings - Fork 93
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
Decode can may fail to unform valid specs #119
Comments
Thanks for the report. Could you provide an example? |
Sure, little contrived but my case boils down to something like this:
|
If you change the multi-spec into: (defmethod blob :a [_]
(st/spec (spec/keys :req-un [:test/a :test/type]))) it works. Without unform, the transformation is only partial: (spec/def :test/a (spec/or :int int? :string string?))
;; not good:
(st/conform :test/blob {:type :a :a 1} st/strip-extra-keys-transformer)
; {:type :a, :a [:int 1]}
;; good
(st/select-spec :test/blob {:type :a :a 1})
; {:type :a, :a 1} hope this helps. |
I guess my issue is more that select-spec shouldn't obviously require the
type to be contained in the spec to work, this requirement is introduced by
the implementation in terms of conform and inform.
…On Mon., 25 Jun. 2018, 05:00 Tommi Reiman, ***@***.***> wrote:
select-spec does both s/confom and s/unform to effectively return the
original value with the extra . The latter fails as the :type key has
been removed by the st/strip-extra-keys-transformer. The spec error is
not very helpful.
If you change the multi-spec into:
(defmethod blob :a [_]
(st/spec (spec/keys :req-un [:test/a :test/type])))
it works. Without unform, the transformation is only partial:
(spec/def :test/a (spec/or :int int? :string string?))
;; not good:
(st/conform :test/blob {:type :a :a 1} st/strip-extra-keys-transformer); {:type :a, :a [:int 1]}
;; good
(st/select-spec :test/blob {:type :a :a 1}); {:type :a, :a 1}
hope this helps.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#119 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AlvrjR900JzKxduqUPLa2F3kUO6Eq3mQks5t_-G6gaJpZM4ULivq>
.
|
I understand, but not sure is there anything we can do for this. https://dev.clojure.org/jira/browse/CLJ-2251 would help as we could just say "coerce" instead of conform + unform. Alex just said that some deep-walking might apper to While waiting - if there is a way to ask from a multi-spec what spec it will dispatch for this given data, we could unform against that spec directly, not for the multispec itself. Don't have time now to try that, but would be a welcome addition to the lib. |
I have a case where I want to use
select-spec
to narrow a map to a subset described by a multi-spec. The multi-spec is dispatched on an item in the larger collection but would be stripped from the final map. This worked fine in previous releases whereselect-spec
was based onconform
(and as a workaround I'm passing thestrip-extra-keys-transformer
toconform
, but I suspect there's an issue withdecode
The text was updated successfully, but these errors were encountered: