Fork me on GitHub
#reitit
<
2019-10-22
>
johan04:10:14

Hi, Trying to grasp coercing with spec. Playing with this ex https://github.com/metosin/reitit/tree/master/examples/http-swagger Why does request params get coerced based on spec, but response do not. {200 {:body {:total pos-int?}}} If my response is :total "123" it won't coerce "123" to 123 and throw and error.

David Pham04:10:42

@johan178 I think the response is more for validation than coercion

David Pham04:10:44

@toni.vanhala thanks. I read it before, but I still could not understand why it was solving problem differently than specs :)

David Pham05:10:41

Wow how did you make it so fast?!

ikitommi06:10:09

@johan178 you can override the muuntaja settings. there should be examples to override the muuntaja transit format readers/writers in both muuntaja docs and hopefully in the reitit docs.

👍 1
ikitommi06:10:24

main focus for reitit 1.0.0 is to get coherent configs (and config errors) for everything. now, it’s… bad.

ikitommi06:10:39

@neo2551 performance is built from bottom-up, by separating compilation & execution. With coercion, the uber case is a deeply nested map+vector schema, where all subschemas can be presented in JSON. The transformation compiler with json-tranformer puns nil out of the pipeline and the top level m/transformer returns identity = “nothing to do”. Can’t beat that 😉

David Pham06:10:25

Haha nice one

ikitommi06:10:51

@rschmukler great explanation. will check the issue comments later today

heyarne13:10:29

hi! love the swagger integration so far but i'm not really experienced with spec… how do i specify optional query parameters?

heyarne13:10:57

and ideally i don't want fully qualified keywords

heyarne13:10:26

I hoped I could just do a (s/nilable string?) but it was still coerced into a required parameter

ikitommi13:10:07

are you using clojure.spec or data-specs?

heyarne14:10:02

I just started sketching out the API, so that's not set in stone

heyarne14:10:03

How are the docs for data-specs? Would it provide a lot of cognitive overhead?

ikitommi14:10:11

for normal specs, use :opt for keys, with data-specs, you wrap the keys with ds/opt.

ikitommi14:10:43

could be a sample of both in the coercion docs...

akiel14:10:08

Hi, is it possible to prevent route conflicts by constrain valid chars in path parameters?

ikitommi17:10:38

@akiel welcome! there are no route guards in reitit, by design. I think such a thing could be built already, but making it performant would be non-trivial.

ikitommi17:10:39

it would basically be linear matching on guarded routes and allowing some kind of guard function to ignore a match (and finding next match).

ikitommi17:10:25

one thing I was thinking was to add a route data hint :conflicting etc, which would allow one to mark conflicting routes manually. This way, if there is just few routes conflicting, marking them would allow the conflict resolution to be enabled for other routes.

akiel17:10:22

Understand. I have routes like Patient/{id} and Patient/_history, were Id’s can’t contain underscores. So in this special case I could think about a performant implementation. But in a general guard case you are right.

ikitommi18:10:53

you can order the routes like so that Patient/_history is first, Patient/{id} is second. If you disable the conflict resolution, they (only the conflicting ones) will be run in order so the first one matches.

ikitommi18:10:57

@tonsky had a nice sorted which reordered the routes automatically so that the wildcards are last, in some gist..

ikitommi18:10:41

actually, it was on pedestal, but ported that to reitit, here’s the gist: https://gist.github.com/ikitommi/d3382348ac50639ae7914ffc0f19bb0f. Original: https://tonsky.me/blog/pedestal/