Fork me on GitHub
#reitit
<
2019-02-13
>
insano1010:02:58

@ikitommi wrapping the body spec in spec-tools worked thanks. However I had to overwrite the version of ring-swagger-ui pulled in as the current one doesn't seem to support examples that are collections (which is what I needed). Also I can't seem to get an example showing for query params, only body. When I wrap a query spec in spec-tools, the parameter just disappears from the generated json entirely. As far as you are aware should this work?

ikitommi10:02:57

didn’t know. For query-params, I think you need to describe the examples per parameter, e.g. :query {:kikka (st/spec int? {:swagger/example 42}), :kukka (st/spec string? {:swagger/example "kukka"}}

ikitommi10:02:35

the spec->swagger could read it from the top-level, but doesn’t do that today. PR/Issue welcome for that.

ikitommi10:02:59

what version of the swagger-ui supports the examples for collections?

insano1011:02:11

I just jumped to the latest version (3.20.1) and that works. Not sure at what point it started though.

insano1011:02:10

Thanks for the query example, will give it a try

tangrammer14:02:55

Hi reitit guys! just looking for some help when you have this kind of routing defned

(ring/router [["/:id" ["" {:get {:responses {200 {}}
                                      :parameters {:path-params {:id string?}}
                                      :handler (fn [{{:keys [id]} :path-params}]
                                                 {:id id})}}]]
                   ["/ole" {:get {:handler (fn [req] {:ok "api/ole"})}}]
                   ["/olo" {:get {:handler (fn [req] {:ok "api/olo"})}}]
                   ])

tangrammer14:02:23

i’m getting this error:

Router contains conflicting route paths:
   
      /:id -> /ole -> /olo

tangrammer14:02:18

I have this kind of routes in a compojure working app so i thought i could translate it directly to reitit :thinking_face:

tangrammer14:02:50

BTW: Thanks in advance for this great library!

tangrammer14:02:59

is there counterproductive point in using {:conflicts (constantly nil)} ?

insano1014:02:20

On an unrelated topic, is it possible to coerce a string parameter to a local date? I was achieving this by accident with a spec that used a conformer with a misconfigured unform fn (used identity) but I've just updated reitit and see the request-coercer now calls st/coerce rather than conform and now keeps the value as a string.

ikitommi14:02:28

@tangrammer thanks! if you set {:conflicts nil}, all the conflicting routes are served with linear-router, in order they are defined. If all the routes are in conflict, it’s bit slower. If you just have few conflicting ones, the perf doesn’t degrade.

ikitommi14:02:12

so, if you have to have conflicts, just disable it.

tangrammer14:02:33

@ikitommi good to know it 🙂 and thanks for the answer!

ikitommi14:02:49

@jdommett request-coercer calls both st/coerce and if that didn’t work, st/conform. I think it should work the same as before. Could you give an example?

insano1015:02:22

Yeh I can see that. My issue was I have wrong code where my unform fn is identity so in the previous implementation it would call conform, all was good, then unform which left all the values conformed. So accidently all is good and my strings come out as localdates. But now coerce is called which appears to leave the strings as is (presumably because I am misunderstanding how coercion should be configured). It coerces fine and so doesn't go on to call conform.

insano1015:02:41

So I want to fix my code by setting the correct unform fn (which would be datetostring) and also work out what magic needs to be sprinkled to get coerce to turn my string into a local date.

insano1015:02:26

I've had a Google but sorry am failing to find the secret sauce.

insano1015:02:26

@ikitommi here is a gist showing an example API that behaves differently using reitit 0.2.0 and 0.2.13 - https://gist.github.com/insano10/a0dda1c10246860d9bfc1b345298c3f1

insano1015:02:11

I'm certain I'm just not defining my specs correctly to get the string turned into a LocalDate, but I'm not sure what to change

insano1015:02:28

Thanks for any help you can give :woman-bowing:

ikitommi05:02:12

@jdommett thanks for gist, I'll dive into that today.

ikitommi13:02:58

@jdommett had time to look the example. here’s a working(?) version: https://gist.github.com/ikitommi/a64314c915cffe46fbd2cef95074a12f

ikitommi13:02:40

so, you need to define the string->date function as a spec-tools transformer and define the actual spec so that it validates that it’s a date.

ikitommi13:02:53

normal clojure.spec conformers should not be used here.

ikitommi13:02:13

hope this helps.

insano1009:02:23

Awesome thanks for that. I'll try it out tomorrow

insano1011:02:33

Yup that works great. Thanks a lot for your help

ikitommi15:02:40

@tangrammer actually, in your case, the two static routes are unreachable, as the first path if tested first and always matches. By design, reitit doesn't support parameter type guards.

👍 5
colliderwriter23:02:38

Hello. I'm a reitit newb so please forgive me if this is obviously wrong but is the pedestal-swagger example missing some resources? When i go to the swagger.json endpoint, i get an unstyled json struct