This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-04-17
Channels
- # bangalore-clj (2)
- # beginners (202)
- # boot (18)
- # cljs-dev (8)
- # cljsjs (7)
- # cljsrn (4)
- # clojars (2)
- # clojure (401)
- # clojure-boston (2)
- # clojure-dusseldorf (1)
- # clojure-gamedev (36)
- # clojure-greece (2)
- # clojure-italy (1)
- # clojure-russia (16)
- # clojure-spec (27)
- # clojure-uk (7)
- # clojurescript (68)
- # core-async (16)
- # cursive (25)
- # datascript (1)
- # datomic (34)
- # funcool (1)
- # hoplon (1)
- # interop (1)
- # klipse (1)
- # leiningen (2)
- # lumo (75)
- # off-topic (17)
- # om-next (2)
- # onyx (66)
- # re-frame (18)
- # reagent (2)
- # ring-swagger (11)
- # spacemacs (1)
- # specter (1)
- # timbre (3)
- # untangled (48)
- # yada (7)
Is there a plan to make an fn spec part of the fn itself, similar to :pre
and :post
? As a piece of metadata, maybe?
Just released spec-provider, a library that will infer specs from sample data: https://github.com/stathissideris/spec-provider
Is there any way to attach metadata to a spec? I want to encode json specs like the following in spec:
"n": {"type": "string",
"readOnly": true,
"description": "Friendly name of the resource"},
this is best i’ve come up with, at least it documents it:
(s/def ::n (s/and string?
(comment {:read-only true
:doc "Friendly name of the resource"})))
spec works great for e.g. https://github.com/OpenInterConnect/IoTDataModels/blob/master/oic.core.json except for meta props like readOnly.
@mobileink there are at least two libs on top of spec which allow meta-data on specs (and produce JSON Schemas): https://github.com/metosin/spec-tools & https://github.com/uswitch/speculate. I’m working on the first one, in which the meta-data is written to spec forms, so the are really persisted. Last PR before releasing, this week hopefully.
thank you. i did take a brief look at spec-tools and saw some spec->json schema stuff; does it go the other way ’round?
no, just one-way currently. @mpenet had plans of doing the other way around, would open up a whole new level of interop with js.
In plain spec, I guess you could add meta-data to registered specs: read the registry value, add meta, re-register.
yeah, was thinking about that but I think I’ll take the path of least resistance and give spec-tools a try. thanks.
I am trying to make generative testing of a recursive spec more feasible. Consider the following simple example:
(s/def ::throne string?)
(s/def ::monarch string?)
(s/def ::gold int?)
(def kingdom (s/spec
(s/keys :req-un [::throne
::monarch
::gold]
:opt-un [::kingdoms])))
(s/def ::kingdoms (s/coll-of kingdom))
Is there an external way to limit the size of the collection produced by s/coll-of
, or is a custom generator necessary?
@waffletower :min-count :max-count allows you to control the collection size.
Thanks! That limits the size supported in the spec though, correct? I am trying to leave the maximum unbounded but place limits to facilitate generation.
I have tried this route:
(s/def ::kingdoms (s/with-gen
(s/coll-of kingdom)
(gen/resize 1 (s/gen (s/coll-of kingdom)))))
this often causes an exception which I am currently tracking down:
ClassCastException clojure.test.check.generators.Generator cannot be cast to clojure.lang.IFn clojure.spec/every-impl/reify--13992 (spec.clj:1285)
Use :max-gen for that
Default is 20 but I find 3 to be better usually
Thanks Alex, need to slow down to see text like: same options as 'every'
🙂
map-of
keys don’t get conformed?
(require '[clojure.spec :as s])
(s/conform
(s/map-of keyword? keyword?)
{"key" :value})
; :clojure.spec/invalid
(s/conform
(s/map-of keyword? keyword?)
{:key :value})
; {:key :value}
(s/conform
(s/map-of (s/conformer keyword) (s/conformer keyword))
{"key" "value"})
; {"key" :value}
no, but you can pass :conform-keys option for that if you need it