Fork me on GitHub
#reitit
<
2019-05-15
>
souenzzo00:05:06

There is some lib that takes swagger "original" description (usually as json) and builds a route for me? something like lacinia does:

(def star-wars-schema
  (-> "schema.edn"
      slurp
      edn/read-string
      (attach-resolvers {:get-hero get-hero
                         :get-droid (constantly {})})
      schema/compile))

ikitommi07:05:26

@souenzzo good question, currently there are no tools, looking forward on someone doing those.

ikitommi07:05:00

biggest thing is to create mappings from swagger json schema => spec/schema. actual path mappings should be easy.

ikitommi07:05:18

dirty sample:

ikitommi07:05:56

There is also https://github.com/zalando-stups/swagger1st, which does the runtime mapping. I think there is a lot to learn from that (haven’t used, but know it exists)

ikitommi07:05:14

wrote issue on that: https://github.com/metosin/reitit/issues/272, help most welcome.

mhcat16:05:46

hmm, I'm having problems compiling a route which contains the following parameters schema (using plumatic for coercions)

:parameters {:body [String]}
- I get an error from deep in meta-merge, which I'll post on a thread. Here's the top line:
Execution error (ExceptionInfo) at reitit.exception/exception (exception.cljc:16).
Don't know how to create ISeq from: java.lang.Class
I guess first question - I don't see any examples using non-map structures in that position, is that unsupported?

mhcat16:05:21

/shrug I guess I can't post this on a thread

ikitommi16:05:59

@j0ni that is supposed to work. Could you minify a non-working router setup to reproduce this?

mhcat16:05:15

let's see if I can 🙂

mhcat17:05:31

😞 it works completely out of context so I will have to piece it together a bit more

ikitommi17:05:22

@j0ni it might be because you have a map body spec defined closer to the root. like this:

(r/router
  ["/kikka"
   {:parameters {:body {:id s/Str}}}
   ["/kakka"
    {:parameters {:body [s/Str]}}]])

ikitommi17:05:53

in that, the meta-merge tries to merge a map and a vector and fails on: Don't know how to create ISeq from: java.lang.Class

ikitommi17:05:20

how to fix: hint meta-merge to override with value:

(r/router
  ["/kikka"
   {:parameters {:body {:id s/Str}}}
   ["/kakka"
    {:parameters {:body ^:replace [s/Str]}}]])

ikitommi17:05:25

hope this helps.

mhcat17:05:08

omg you're right

ikitommi17:05:50

the error message could be better…

mhcat17:05:08

definitely - but thank you, and I expect this will de-mystify future similar encounters 🙂

ikitommi19:05:13

@j0ni how about:

(ns user
  (:require [reitit.core :as r]
            [schema.core :as s]
            [reitit.dev.pretty :as pretty]))

(r/router
  ["/kikka"
   {:parameters {:body {:id s/Str}}}
   ["/kakka"
    {:parameters {:body [s/Str]}}]]
  {:exception pretty/exception})

mhcat19:05:26

that's way better than the current message for sure - it points to the problem