Fork me on GitHub
#ring-swagger
<
2018-06-22
>
ikitommi12:06:31

@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:

ikitommi12:06:35

(def app
  (api
    {: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 "[email protected]"],
; :muuntaja/format "application/msgpack"}

ikitommi12:06:09

the next alpha will fail with invalid input:

ikitommi12:06:12

(def app
  (api
    {: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.

Andreasp199413:06:50

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

Andreasp199413:06:26

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

jdt14:06:51

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.

jdt14:06:47

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.

Andreasp199414:06:23

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

jdt14:06:40

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.

Andreasp199414:06:17

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

jdt14:06:58

Sorry, don't know.

jdt14:06:33

If you're truly stuck perhaps dynamic bindings?

jdt14:06:59

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

Andreasp199414:06:19

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

Andreasp199418:06:26

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?

Andreasp199418:06:19

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