This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-27
Channels
- # aleph (5)
- # announcements (18)
- # beginners (200)
- # cider (25)
- # cljdoc (4)
- # cljsrn (3)
- # clojure (90)
- # clojure-europe (3)
- # clojure-finland (5)
- # clojure-france (1)
- # clojure-houston (1)
- # clojure-italy (8)
- # clojure-nl (15)
- # clojure-spec (24)
- # clojure-uk (20)
- # clojurescript (199)
- # core-async (2)
- # cursive (45)
- # data-science (14)
- # datomic (33)
- # duct (13)
- # fulcro (4)
- # graphql (3)
- # kaocha (9)
- # leiningen (24)
- # nrepl (16)
- # off-topic (105)
- # pathom (15)
- # pedestal (28)
- # re-frame (1)
- # reagent (14)
- # shadow-cljs (28)
- # spacemacs (8)
- # tools-deps (8)
- # vim (4)
@zclj haven’t heard, but would have use for that too. there is an issue in spec-tools, but no work going on: https://github.com/metosin/spec-tools/issues/154. Happy to help if someone starts doing that.
@ikitommi thanks for the info. I will do some experiments on my specific case and if it is generic enough I would be happy to contribute to the issue in spec-tools
Is there a way to force a fdef
to validate always the inputs? Schema had the :always-validate
metadata for this.
e.g.
(require '[schema.core :as s])
(s/defn ^:always-validate interceptor-x
[opts :- {:string? s/Bool}]
...)
(interceptor-x {})
; Syntax error (ExceptionInfo) compiling at (test.cljc:150:1).
; Input to interceptor-x does not match schema:
;
; [(named {:string? missing-required-key} opts)]
Not that I know of.
You can use a :pre
condition on a function that calls s/valid?
, though you’ll not get an s/explain-*
style error if you do.
If you actually want that though, why can’t you just call
(st/instrument #{`the.fdef.i.want.to.always/validate})
I’d probably just call s/valid?
and raise an s/explain-data
if the check failed explicitly inside the function though if I wanted that — or however you want to report the error.
It would if it was both an fdef and that 🙂
calling clojure.spec.test.alpha
from non-test code also doesn’t sound like a good idea.
regarding configuring components on startup you might want to look at what integrant does: https://github.com/weavejester/integrant/#specs
That’s nice, thanks! Doing about the same with reitit: https://github.com/metosin/reitit/blob/master/modules/reitit-http/src/reitit/http/coercion.cljc#L12
I would still like a support functional way of doing that: have a function that takes options and returns the component (that has a spec). And the function args should be validated too.
@ikitommi I’m not sure it addresses your exact issue, but orchestra’s instrument
enables checking of :ret
and :fn
this has been better for how we use spec; where we enable instrumentation during development to try and get type-checking-like feedback while writing code
@ikitommi it is intentional that this functionality doesn't exist for functions as the goal is to have no overhead for function specs at runtime
but I'll leave it open for now as maybe it would be useful to have an opt-in feature for that