This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-25
Channels
- # arachne (1)
- # beginners (22)
- # boot (21)
- # cider (23)
- # cljs-dev (16)
- # cljsrn (9)
- # clojure (118)
- # clojure-dev (11)
- # clojure-greece (16)
- # clojure-italy (10)
- # clojure-losangeles (4)
- # clojure-russia (14)
- # clojure-serbia (4)
- # clojure-spec (58)
- # clojure-uk (33)
- # clojurescript (30)
- # cursive (17)
- # datomic (48)
- # docs (22)
- # events (1)
- # fulcro (24)
- # hoplon (3)
- # jobs (6)
- # jobs-discuss (4)
- # keechma (4)
- # leiningen (11)
- # luminus (4)
- # midje (1)
- # off-topic (107)
- # onyx (30)
- # other-languages (12)
- # pedestal (4)
- # re-frame (72)
- # reagent (6)
- # remote-jobs (1)
- # shadow-cljs (16)
- # spacemacs (3)
- # specter (9)
- # uncomplicate (4)
- # unrepl (40)
@ikitommi Thanks, but I don't want to generate swagger, but the data consumed by the interfaces specified in a swagger file. It doesn't look like that is possible with swagger-spec?
oh, the endpoint data. With vanilla swagger spec, there needs to be a JSON-Schema -> Spec converter, I don’t know if such exists yet. But if you describe your endpoints with spec, you get the data generation for free.
Yes, already doing that, unfortunately some of the other services in my project aren't written in Clojure. If one were to write such a converter, how would one go about it? I invested an afternoon because I didn't really find anything too, but it seemed really hard and messy to generate specs at runtime, due to its reliance on global mutable state 😞
@ikitommi I saw that you had schema like maps in your spec tools, which could be handled like normal data. Would that be an option for this case?
Some more “functional specs” might be coming to core, but while waiting, yes, there are some rogue versions at https://github.com/metosin/spec-tools/blob/master/src/spec_tools/data_spec.cljc#L8-L10 and the data-specs on top of those.
most/all of the core specs have functional versions already in the core, but currently not documented and the apis are bit hairy. Maybe those will be polished and published as part of the public api? The forms need to be created manually but for most core predicates, it’s easy to resolve those (and spec-tools does that already)
Hm, I see. Thanks, I'll give it a go, and hope for the release of the functional api in core.
is there something like s/cat but that doesn't do any labeling? need to match a subsequence within a sequence without too much ceremony
it's a seq of chars (just playing), so nothing generic, I need equality matching (ex match (b a r) in (f o o b a r b a z))
if you don’t want labeling, just use s/valid?
all the surounding value have a meaning that I need to retain also, I can't just check "does this seq contains this sub-seq"
you can use s/& to apply a custom predicate to a regex spec
which could be helpful here
that's brilliant, I was messing with conformers but I think & might just do all this for me
that is, if I reload a namespace that has (def foo (some-instrumented-fn invalid-value))
, does reloading the ns throw an exception?
Reloading is going to remove your instrumented vars
what checks?
that seems pretty far from the original questions :)
I’m not very familiar with either clojure.test or spec, so I’m fumbling around a bit 🙂
there used to be a pin here to an example, but maybe it has aged out
by “check specs”, I’m assuming you mean to run clojure.spec.test.alpha/check on one or more spec’ed functions
actually, I want to check with s/valid?
, but use s/explain
instead of the usual error message provided by is
so s/valid? is not going to be as useful in checking spec’ed functions as is calling check
unless ::my-spec here refers to a data spec
I can’t really tell
sorry if my questions are a bit confused, it’s hard to ask good questions when you’re not familiar with something
yep, no worries
I am similarly trying to re-interpret your questions :)
so you want to check if some data matches a spec and if not, return a message that is s/explain
one way would be to:
(is (nil? (s/explain ::spec data)))
although I guess you want the explain result as a value not as a print
(is (not= "Success!\n" (s/explain ::spec data)))
would do that I think
that’s quite ugly of course :)
yeah, can do same idea with explain-data
you can supply a final custom error message to is
too
so something like: (is (valid? ::spec data) (s/explain-str ::spec data))
?
I went with this:
(defmacro spec-is [spec value]
`(is (nil? (s/explain-data ~spec ~value))))
A shameless plug, but you can also add a message to is
. With expound you could do something like
(defmacro spec-is2 [spec value]
`(is (s/valid? ~spec ~value)
(expound/expound-str ~spec ~value)))
which will give you output like:
FAIL in (test2) (alpha_test.cljc:2152)
-- Spec failed --------------------
1
should satisfy
#{:c :b :a}
-------------------------
Detected 1 error
expected: (clojure.spec.alpha/valid? #{:c :b :a} 1)
actual: (not (clojure.spec.alpha/valid? #{:c :b :a} 1))