ring-swagger

ring-swagger & compojure-api
Misha Bohdan 2019-08-15T11:53:46.024100Z

Hello! Is there a way to prevent conversion from clojure.spec to spec-tools.core/Spec objects using compojure.api? PS: I don’t need a swagger schema at all.

ikitommi 2019-08-15T12:15:41.026200Z

@bohdan.mikhail mostly you don't need to wrap anything into Specs. Sometimes you do, can't recall all the cases, here are the docs https://cljdoc.org/d/metosin/spec-tools/0.10.0/doc/spec-driven-transformations

ikitommi 2019-08-15T12:17:01.028400Z

if people need coercion with spec, please poke the Cognitect core devs. Currently out-of-scope, and spec-tools has to do dirty tricks to make it work.

ikitommi 2019-08-15T12:17:26.029100Z

direct support from spec would make things so much better

ikitommi 2019-08-15T12:18:20.030100Z

(and faster)

Misha Bohdan 2019-08-15T13:13:38.031500Z

I don’t do that. I just need to reverse parse explain-data output but after spec-tools I’ll get spec-tools.core/Spec object instead of a keyword in :spec field.

ikitommi 2019-08-15T13:55:52.031700Z

that’s unfortunate. It could nowadays work without the automatic wrapping as spec-tools changed from conforming-based coercion to form-based. But don’t have extra time to try that one out. The wrapping is in the spec-coercion namespace. You could try to remove that and see if everything works.

borkdude 2019-08-15T15:14:45.032Z

Any reason Metosin implements its own validation library instead of adopting JSON Schema? You might have had this question a 100x by now, just curious.

borkdude 2019-08-15T15:14:52.032200Z

(I just saw the juxt blog post)

ikitommi 2019-08-15T15:52:43.038Z

@borkdude there is rationale in README (https://github.com/metosin/malli/blob/master/README.md#motivation). Is is modelled from JSON Schema, which is imo, good for tooling but has really bad developer ux. Also, bit of NIH ;)

borkdude 2019-08-15T15:54:02.040Z

😄

ikitommi 2019-08-15T15:54:09.040300Z

Have started with JSON Schema in few projects, but ended up cooking a ad-hoc clojure data definition language for form generation.

ikitommi 2019-08-15T15:54:44.041300Z

now just wrapping all ideas as a lib. Also, will be really, really, fast

ikitommi 2019-08-15T15:55:35.042600Z

Currently 370 lines, does validation, full programming errors (e.g. spec explain-data) and coercion.

ikitommi 2019-08-15T15:56:15.043700Z

And it's all data :)

borkdude 2019-08-15T15:56:22.044Z

nice. did you know juxt was developing jinx at the same time?

borkdude 2019-08-15T15:56:32.044500Z

it seems now we have two new libs to choose from in this space 🙂

ikitommi 2019-08-15T15:56:47.044800Z

no, found it few days ago.

ikitommi 2019-08-15T15:58:46.047500Z

seems like jinx was started bit earlier than malli. Spec doesn't seem to deliver all the things we need as the libs keep popping up..

borkdude 2019-08-15T15:59:11.047900Z

yeah, being able to serialize these things is a nice property of "just data"

ikitommi 2019-08-15T16:00:42.049200Z

Need to test jinx, good to have options.

borkdude 2019-08-15T16:18:24.050600Z

so you can have a custom predicate registry but if you serialize it to some other party, you have to ensure that party also has that same function registered, right?

borkdude 2019-08-15T16:19:56.051700Z

it reminds me a bit of something I made: https://github.com/borkdude/sci this enables you to evaluate a string of Clojure code safely in CLJS and CLJ, so you can just create any function you want from safe ingredients

borkdude 2019-08-15T16:20:09.052100Z

and you can send that string back and forth

borkdude 2019-08-15T16:20:56.052800Z

this way you could ensure that the other party registers a custom function under the same key as you did

borkdude 2019-08-15T16:21:54.053200Z

but I guess you can go a long way with just plain data structures

ikitommi 2019-08-15T17:21:19.061900Z

@borkdude yes, all parties need to have the same registry if there is custom predicates (like EDN & Transit has readers & writers) - unless the code is passed around too. Would be nice to do a poc sci for that. Have you thought about things like security and the halting problem?

ikitommi 2019-08-15T17:21:28.062100Z

Currently are already some helpers to compose higher level schemas from data, like [:and {:id :domain/age, :name "Age, must be over 18"} int? [:> 18]].

ikitommi 2019-08-15T17:22:06.062300Z

reminds me of https://twitter.com/stuartsierra/status/1156687604798148610 🙂

borkdude 2019-08-15T17:59:27.064700Z

@ikitommi security: you shouldn't trust the code, but you can trust the evaluator, since you decide what goes in. halting problem: yeah, you can do (reduce (fn [_ x] x) (range)) I guess, I have no answer to that except for maybe executing in in a future with a timeout?

borkdude 2019-08-15T18:00:34.065400Z

currently sci only has "pure" functions from clojure by default, but you can register additional "dangerous" functions and values at your own risk

borkdude 2019-08-15T18:02:38.066300Z

maybe an option to only register some functions like predicates and other combinators that are guaranteed to terminate will work

👌 1
ikitommi 2019-08-15T18:04:08.066800Z

that would be super! wrote https://github.com/metosin/malli/issues/35#issuecomment-521737930

borkdude 2019-08-15T19:05:48.067500Z

that would be super easy to implement (only explicitly allowing certain functions). I'd say just try it out if it's useful at all and then I'd be happy to implement it after you let me know in an issue

borkdude 2019-08-15T19:06:02.067800Z

@ikitommi ^

ikitommi 2019-08-15T20:52:25.068800Z

will try, thanks @borkdude