This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-01
Channels
- # beginners (133)
- # boot (59)
- # cider (5)
- # cljs-dev (30)
- # cljsrn (23)
- # clojure (212)
- # clojure-austin (3)
- # clojure-brasil (1)
- # clojure-chicago (5)
- # clojure-italy (10)
- # clojure-russia (5)
- # clojure-serbia (1)
- # clojure-spec (34)
- # clojure-turkiye (2)
- # clojure-uk (132)
- # clojurescript (163)
- # clojutre (1)
- # cursive (5)
- # datomic (58)
- # emacs (42)
- # events (1)
- # graphql (26)
- # hoplon (16)
- # jobs (1)
- # lumo (27)
- # numerical-computing (3)
- # off-topic (127)
- # om (9)
- # onyx (24)
- # re-frame (20)
- # reagent (20)
- # ring-swagger (14)
- # sql (19)
- # unrepl (28)
- # untangled (3)
- # vim (8)
- # yada (17)
like
(gen/sample
(gen/fmap (fn [[name host]] (format "%s@%s" name host))
(s/gen (s/tuple #{"fred" "tom" "mary"}
#{"" ""}))))
@misha I’d echo Sean’s advice -either don’t spec the ids, or spec them with an s/or (validation and gen will work better then), or combine an entity spec with an additional id spec if needed in some places, etc.
hey all I was wondering if there is a tool around that would take a swagger spec and transform it to a clojure spec
@alexmiller is your f/map
approach superior in some way to the following? Or is it just a matter of taste?
;;clojure.test.check.generators/let
(gen/sample
(tgen/let [name (s/gen #{"fred" "tom" "mary"})
host (s/gen #{"" ""})]
(format "%s@%s" name host)))
How do I define a spec with a generator? e.g. (spec/def ::letter (spec/and (gen/char-alpha) #(Character/isUpperCase %)))
I think the spec/gen
in your custom generator is the problem
Is (gen/char-alpha)
not already a generator?
@andrewmcveigh https://github.com/clojure/test.check/blob/master/doc/cheatsheet.md#characters--strings--things
(spec/def ::letter (spec/with-gen
(spec/and char? #(Character/isUpperCase %))
#(gen/char-alpha)))
(spec/exercise ::letter)
=>
([\S \S] ...)
why not?
@stbgz have been waiting for someone to do the json schema -> spec converter too. Would also enable things like server code-gen from swagger-spec to a clojure(.spec) web server. Might help the enterprise adoption.
there are spec-tools & speculate which do the spec -> json schema. and spec-swagger for spec -> swagger (only 80% done)
is there a recursive version s/describe
which returns definitions of any specs referenced in the top level spec? Kinda like a macroexpand-all?
@danieleneal - you could use the spec-visitor from spec-tools: https://github.com/metosin/spec-tools#spec-visitors
So I am experimenting with setting up specs for http://aleph.io/manifold/deferreds.html
Part of the problem is because deferred are used encapsulate async code and unrealized values the only way I can think of to check the spec is to use a wrapper function that unwraps the value and checks the spec
@grierson recommendation: use s
as the alias instead of spec
, I say that because it's a standard name for everybody, going away from well defined conventions is not a good ideia
@wilkerlucio I was following this guideline http://tonsky.me/blog/readable-clojure/.
@grierson yeah, this article is a bit contrived, I recommend you check this one from Stuart Sierra: https://stuartsierra.com/2016/clojure-how-to-ns.html
@wilkerlucio Thank you, I will check it out.
you'r welcome 🙂
@grierson that article has the right idea but we make exceptions for very-widely-used libraries. in those cases there's often a shorthand convention rather than following the rule
@misha one benefit of my approach is that I use only generators built from clojure.spec.gen.alpha, which uses dynamic loading, which means that you don’t need test.check at runtime to load the namespace. other than that, personal preference.
@danieleneal no, there is not a deep-describe, but it’s something we’ve talked about adding. I think having spec specs (CLJ-2112) would be a big help for this to generically walk specs to find sub specs, so I’ve kind of filed it behind that one. Another alternative would be to actually support this as some kind of recursive op built into the protocol.