Fork me on GitHub
#reitit
<
2019-12-10
>
ikitommi06:12:50

@doubleagent you might be using too old version of Clojure, qualified-keyword? was added in 1.9

ABeltramo09:12:49

It's possible to set optional params or put some default overridable values so that users can make a request without passing them? I searched thru the docs without luck.

:parameters {:body {:image            (st/spec {:spec string? :swagger/default "/9j/4AAQSkZJRgABAQAAAQABAAD ..."})
                    ; Can I make the following optional?
                    :mask-size        (st/spec {:spec (s/nilable nat-int?) :swagger/default "8"}) ; I tried using nilable with no luck..
                    :mask-probability (st/spec {:spec (s/nilable double?) :swagger/default "0.5"})
                    :batch-size       (st/spec {:spec (s/nilable nat-int?) :swagger/default "30"})}}
In this case I would like to express that image must be passed and other params are optional. Am I missing something?

ABeltramo10:12:26

Thanks for the quick reply but I don't see how that can apply to my issue. Maybe I didn't explain well my issue.

ikitommi10:12:10

(ds/opt :mask-size)

ikitommi10:12:00

... or you can use normal s/keys with :opt

ABeltramo10:12:45

I see, thanks. I'll take a deeper look at data-specs then..

ABeltramo10:12:03

Sorry to bother you, where should I put the data-spec definition? I tried

:parameters {:body {:image            (st/spec {:spec string? :swagger/default "/9j/4AAQSkZJRgABAQAAAQABAAD ..."})
                    :mask-size        (ds/opt nat-int?)
                    :mask-probability (ds/opt double?)
                    :batch-size       (ds/opt nat-int?)}}
and
:parameters {:body {:image            (st/spec {:spec string? :swagger/default "/9j/4AAQSkZJRgABAQAAAQABAAD ..."})
                    ; Can I make the following optional?
                    :mask-size        (st/spec {:spec (ds/opt nat-int?) :swagger/default "8"}) ; I tried using nilable with no luck..
                    :mask-probability (st/spec {:spec (ds/opt double?) :swagger/default "0.5"})
                    :batch-size       (st/spec {:spec (ds/opt nat-int?) :swagger/default "30"})}}
and
:parameters {:body {:image            (st/spec {:spec string? :swagger/default "/9j/4AAQSkZJRgABAQAAAQABAAD ..."})
                    :mask-size        (ds/spec (ds/opt nat-int?))
                    :mask-probability (ds/spec (ds/opt double?))
                    :batch-size       (ds/spec (ds/opt nat-int?))}}
and
:parameters {:body {:image            (st/spec {:spec string? :swagger/default "/9j/4AAQSkZJRgABAQAAAQABAAD ..."})
                    :mask-size        (ds/spec {:spec {::size (ds/opt nat-int?)}})
                    :mask-probability (ds/spec {:spec {::prob (ds/opt double?)}})
                    :batch-size       (ds/spec {:spec {::batch (ds/opt nat-int?)}})}}
but I still got Request coercion failed if I'm not passing one of the optionals.

ikitommi10:12:41

the ds/opt shoudl wrap the key.

ikitommi10:12:05

:parameters {:body {:image              (st/spec {:spec string? :swagger/default "/9j/4AAQSkZJRgABAQAAAQABAAD ..."})
                    (ds/opt :mask-size) nat-int?}}

ABeltramo10:12:01

I'm afraid that it's not working. I still got coercion failed [...] (clojure.core/contains? % :mask-size)

ikitommi10:12:22

could you paste the final code here?

ABeltramo10:12:36

My bad, manual shut down and reload the JVM sorted it out. Thanks for the help, seems working now.

crinklywrappr15:12:07

I've got this namespace: http://dpaste.com/0D5VRNM. If make changes to hello-world and re-eval then I am able to see the changes after a page refresh. However, if cc-routes looks like this: ["/" {:get hello-world}] I won't see changes after a re-eval. What's the difference?

ikitommi15:12:42

@doubleagent the routes are compiled (and cached) when a router is created. To reset the router after changes in routes, you should use a tool like tools.namespace , Integrant-repl or a file watcher

ikitommi15:12:59

... PR for guide on different ways to resolve this are most welcome.

crinklywrappr15:12:09

@ikitommi are you saying the router doesn't lookup hello-world when the second form is used?

crinklywrappr15:12:33

instead it uses a cached version of the function

crinklywrappr15:12:16

for performance, i'm guessing?

crinklywrappr16:12:50

I worked around it by wrapping the call to ring-handler in a fn which takes a request.

crinklywrappr16:12:32

ah, thanks. probably should have read through this first

ikitommi16:12:41

Not the easiest to find, feel free to make the docs better