Fork me on GitHub
#reitit
<
2018-11-14
>
ikitommi06:11:57

I think parts of the ring-defaults could be wrapped into Middleware maps, so that we could be inspected & inventoried easier. Also the implementation & configuration could be revisited: via middleware parameters or via route data. Both ways, the configs should be specced.

ikitommi06:11:48

And not sure where these things should reside.

arlicle16:11:00

when i use [metosin/reitit "0.2.7"], I want config optional-key , [schema.core :as s] , when I write this code is right, :parameters {:query {:x int?, :y int?}} but when I change to :parameters {:query {:x s/Int, :y s/Int}}, I get a error Exception in thread "main" java.lang.Exception: Unable to resolve spec: :clojure.spec.alpha/unknown, compiling:(core.clj:43:5), or I write this :parameters {:query {(s/optional-key :x) s/Int}}, I get error Exception in thread "main" java.lang.Exception: Unable to resolve spec: :x, compiling:(core.clj:43:5), How can I fix it 🙂

ikitommi17:11:01

@arlicle you can’t mix spec & schema syntax: {:x int?, :y int?} uses data-spec syntax (https://cljdoc.org/d/metosin/reitit/0.2.8-SNAPSHOT/doc/coercion/data-specs), {:x s/Int, :y s/Int} is Schema (https://cljdoc.org/d/metosin/reitit/0.2.8-SNAPSHOT/doc/coercion/plumatic-schema)

ikitommi17:11:06

to have optional-key with data-specs try:

(require '[spec-tools.data-spec :as ds])
{(ds/opt :x) int?, :y int?}

ikitommi17:11:29

or you can change the coercion to Schema and use the s/optional-key.

kanwei19:11:50

since reitit uses a segment tree, ordering of routes doesn't really matter right?

ikitommi19:11:15

@kanwei yep, doesn't matter unless you force a linear-router.

ikitommi19:11:07

you can have million wildcard routes and you static paths still match in 30ns

kanwei19:11:11

also is this kosher?

kanwei19:11:13

["/assets/swagger/*"
      {:handler    (constantly nil)
       :middleware [#(swagger-ui/wrap-swagger-ui % {:path "/api/assets/swagger/"})]}]

kanwei19:11:16

or is there a better way

kanwei19:11:29

one of the reasons i wanted to switch was to only run middleware on certain routes and not on the top level

kanwei19:11:46

the code works like this, but it there room for improvement?

ikitommi19:11:08

you can use the swagger-ui/create-swagger-ui-handler as a handler too

ikitommi19:11:45

both work, just less boilerplate with the handler

arlicle22:11:01

@ikitommi thank you very much 🙂