ring-swagger & compojure-api
ikitommi 2018-06-22T12:39:31.000434Z

@dave.tenny there was a broken safety assertion. having a :format key in the options, should fail with a descriptive message to use :formats. Fixed it, try this:

ikitommi 2018-06-22T12:39:35.000008Z

(def app
    {:formats (m/create (-> m/default-options (msgpack/with-msgpack-format)))}
    (GET "/" []
      (ok {:kikka "kukka"}))))

(app {:uri "/", :request-method :get, :headers {"accept" "application/msgpack"}})
;{:status 200,
; :headers {"Content-Type" "application/msgpack; charset=utf-8"},
; :body #object[java.io.ByteArrayInputStream 0x43296161 "java.io.ByteArrayInputStream@43296161"],
; :muuntaja/format "application/msgpack"}

ikitommi 2018-06-22T12:40:09.000011Z

the next alpha will fail with invalid input:

ikitommi 2018-06-22T12:40:12.000069Z

(def app
    {:format (m/create (-> m/default-options (msgpack/with-msgpack-format)))}
    (GET "/" []
      (ok {:kikka "kukka"}))))
;CompilerException java.lang.AssertionError: Assert failed: ERROR: Option [:format] is not used with 1.2.0 or later.
;Compojure-api uses now Muuntaja insted of ring-middleware-format,
;the new formatting options for it should be under [:formats]. See
;[[api-middleware]] documentation for more details.

ikitommi 2018-06-22T12:46:06.000017Z

@dave.tenny error should fixed in the next version: https://github.com/metosin/compojure-api/commit/0e90808623597de85069e384c88211ec10ea5210

Andreasp1994 2018-06-22T13:40:50.000313Z

Hey are there any examples for having authenticated and unauthenticated endpoints with compojure api and swagger?

Andreasp1994 2018-06-22T13:42:26.000576Z

Also how can I add the authentication middleware to compojure api routes in case it has more than 1 parameters?

jdt 2018-06-22T14:07:51.000479Z

This may not answer your question, but we use things like buddy.auth.middleware/wrap-authentication in our ring handlers for authentication. I'm not clear on how we manage to have a mix of authenticated and unauthenticated endpoints even though I implemented it. Ultimately ring handers for all though, I think.

jdt 2018-06-22T14:19:47.000678Z

Ah, there it is. Our authenticated endpoints use a context with :middleware option and authentication routines. Our unauthenticated enpoints aren't grouped in that context. I know, a code sample would help but can't easily give you one.

Andreasp1994 2018-06-22T14:25:23.000181Z

@dave.tenny Nice I think I understand what you mean.. what if your middleware have more than the handler parameters?

jdt 2018-06-22T14:27:40.000493Z

I'm unclear on what you mean about the handler parameters. However note that you can update the request as it's passed down the handler chain, adding headers. E.g. if you've authenticated a user you might add a user or identity token to the headers. I think. It's been a while since I worried about this stuff.

Andreasp1994 2018-06-22T14:29:17.000565Z

Right.. What I mean is that normally a middleware wrapper will be of arity 1 and take a ring handler as a parameter and then it is just injected in the :middleware keyword. In my case my middleware has additional dependencies which I am not sure how to pass in the :middleware keyword

jdt 2018-06-22T14:31:58.000360Z

Sorry, don't know.

jdt 2018-06-22T14:32:33.000685Z

If you're truly stuck perhaps dynamic bindings?

jdt 2018-06-22T14:32:59.000029Z

I still consider myself to be a ring/compojure rookie, so I'll bow out of the lame suggestion department for now.

Andreasp1994 2018-06-22T14:33:19.000384Z

No problem thanks for your help! really appreciate I may even got this wrong in the first place since I am a rookie as well xD

Andreasp1994 2018-06-22T18:02:26.000020Z

Any ideas why I get CompilerException java.lang.IllegalArgumentException: Don't know how to create ISeq from: clojure.lang.Symbol when passing a binded vector into :middleware rather than passing it directly?

Andreasp1994 2018-06-22T18:03:19.000528Z

for instance :middleware [] works fine but (let [mw []] ( ... :middleware mw ...)) throws the above error