Fork me on GitHub
#clojure-spec
<
2017-03-22
>
mpenet08:03:11

spec made me use derive for the first time in 7 years 🍾

yonatanel08:03:27

@mpenet What did it solve? :)

mpenet08:03:18

trying a new approach to generate json-schemas from specs, I have a registry of specs/preds -> json-schema forms that's a multimethod and that allows me to have some form of inheritance

yonatanel08:03:24

Can you show an example? I'm not sure what json-schema is or how you convert from spec to json-schema.

mpenet08:03:45

json-schema is the format used by swagger/open-api

mpenet08:03:52

well part of

ikitommi08:03:23

does the end result look different than the spec-tools conversion? (also uses a multimethod, but no inheritance atm)

mpenet08:03:10

not sure, I didn't look into spec-tools internals too much. What do you mean by end result?

ikitommi08:03:07

mapped all the predicates that have a clojure.spec generator, with those “rules”, here: https://github.com/metosin/spec-tools/blob/master/src/spec_tools/json_schema.cljc

mpenet08:03:18

looks very similar, but to be able to use derive you need to have ns'ed keywords

mpenet08:03:33

the same can be achieved with a macro tho, nothing too fancy

mpenet08:03:18

stuff I did is also an experiement with CLJ-2112

mpenet08:03:48

I am using a slightly modified/fixed version of that patch

yonatanel08:03:35

@ikitommi That's a nice lib đź‘Ť

ikitommi08:03:41

derive looks nice. should we at some point merge the working stuff into XYZ? would like to copy-paste the some of the missing mappings from Spex already.

mpenet08:03:02

feel free to do that, spex is just a test-bed really

mpenet08:03:42

seems like spec-tools covers a lot more already tho

ikitommi08:03:19

it’s missing the Coercion protocol (instead of dynamic conforming), after it I’m kinda happy with what tries to resolve. the “drop-extra-keys from maps” things etc.

ikitommi08:03:36

the 2112 would be awesome, it’s messy without that. Just realized yesterday that one can use and and or with s/keys...

mpenet08:03:39

these are different approaches really, spec-tools seems to wrap all specs with it's own types to add "metadata", coercion etc, I just force the user to register its specs (and provide some defaults) and don't bother with coercion at all at this level (imho these are 2 different things)

mpenet08:03:06

spec-tools is full of cool stuff, didn't see the spec maps format thing

mpenet08:03:32

yeah or/and in keys is a bit of a pita, not sure it's feasible to translate in json-schema

mpenet08:03:15

CLJ-2112 code conforms it happily, but it's just ignored for convertion down the road

ikitommi08:03:54

spec-tools doesn’t force to wrap into own records, JSON Schema is extracted from normal spec forms. Own records can be used to add metadata.

mpenet09:03:46

I guess for or/and in keys one should/could just flatten all of it when generating a schema

mpenet12:03:44

I think I like spec-tools approach better, records make all of this way nicer internally, too bad core.specs are not defined this way