Fork me on GitHub
#yada
<
2017-03-28
>
jonathanj07:03:44

Sorry if this conversation has already happened, but has the Swagger (OpenAPI) 2.0 API inspired any changes in yada?

malcolmsparks07:03:01

yada already supports OpenAPI 2.0. Is there something missing?

malcolmsparks07:03:43

Afk. Will have to check later

jonathanj07:03:15

Oh, I didn't know. I thought it was only recently announced.

mpenet07:03:03

3.0 is RC, but 2.x has been here for a while I think

jonathanj07:03:18

Oh, sorry, off-by-one error.

mpenet07:03:23

common mistake šŸ™‚

malcolmsparks07:03:26

Yes. I think yada does NOT support 1.x

lsnape19:03:03

Iā€™m going wrong here somewhere:

(yada/listener (fn [{:keys [request] :as ctx}]
                   (-> (get-handler request)
                       (handle-request request ctx)))
                 {:port port})

lsnape19:03:50

Where get-handler returns a yada handler. The error Iā€™m getting is: Cannot JSON encode object of class: class java.nio.HeapByteBuffer: java.nio.HeapByteBuffer[pos=0 lim=4 cap=4]

dominicm19:03:43

@lsnape did you add to the protocol for yada & functions?

lsnape19:03:56

No, I donā€™t think I need to because get-handler is returning a #yada.handler.Handler right?

lsnape19:03:18

Letā€™s say that this is get-handler:

(defn get-handler
  [request]
  (yada ā€œpongā€))

dominicm19:03:44

The first argument to listener shouldn't be wrapped in fn

dominicm19:03:30

I don't really understand what you're trying to achieve

lsnape19:03:53

I have my own way of matching the yada handler from the uri in the request

lsnape19:03:14

listener does accept a function as its first argument, which is needed for the use case where something other than bidi or yada decides which resource handles the request.

dominicm20:03:17

I thought it called as-handler on it? Which when I last tried didn't support that :thinking_face:

dominicm20:03:54

You have to extend-protocol for clojure.lang.Fn for that to work.

dominicm20:03:04

@lsnape what version of yada are you using :thinking_face: ?

lsnape20:03:50

@dominicm Iā€™m using version 1.2.1

lsnape20:03:21

Iā€™m calling handle-request with 3 args above

lsnape20:03:03

Sorry needless threading is a terrible habit of mine

kardan20:03:02

Anyone tried to use Yada with Integrant?

kardan20:03:36

I seem to run into some issue with Aleph "SEVERE: Failed to submit a listener notification task. Event loop shut down? java.util.concurrent.RejectedExecutionException: event executor terminated"

kardan20:03:04

When I do (halt) and then try to do any of the integrant.repl commands after

lsnape20:03:30

kardan: Iā€™m using yada with integrant. I have seen an ā€˜event executor terminatedā€™ message, but didnā€™t attribute it to integrant.

kardan20:03:33

(realise this might been the wrong chat for this)

lsnape20:03:33

What makes you think that itā€™s integrant?

lsnape20:03:15

dominicm, just looking through the handler ns to see if I can find any clues!

dominicm20:03:24

lsnape I'm not certain how you're calling yada/listener. Are you sure you've no code like:

(extend-protocol HandlerCoercion
  clojure.lang.Fn
  (as-handler [this] this))

kardan20:03:16

Iā€™m not sure what the problem is at the moment. But as you imply, I should try to limit the options

lsnape20:03:27

Nope. I assure you the above works out of the box šŸ™‚

lsnape20:03:44

Good luck kardan!

lsnape20:03:12

This returns a yada handler: (as-handler (fn [ctx]))

dominicm21:03:20

Anyway, I can reproduce with:

(fn [{:keys [request] :as ctx}]
                                      (yada.handler/handle-request
                                        (yada/resource {:methods {:get {:response (fn [ctx] {:from-resource :foo})}}})
                                        request
                                        ctx))

dominicm21:03:42

But I'm requesting html, but getting the bytebuffer back

lsnape21:03:32

So handle-request returns a deferred. Iā€™ve inspected (dereffed) it and it looks OK

dominicm21:03:04

@lsnape the problem is that you're returning a ring request string, and yada is expecting the return value of your response function here.

dominicm21:03:18

I'm not sure on the correct implementation of course šŸ™‚

dominicm21:03:42

@lsnape Not sure what protocol is matching, but if you do:

(extend-protocol HandlerCoercion
  clojure.lang.Fn
  (as-handler [this] this))
the world is happy :thinking_face:

dominicm21:03:44

Or rather, you can return a deferred & it's happy

dominicm21:03:53

oh, check the keys in ctx

dominicm21:03:20

@lsnape This works:

(fn [req]
  (yada.handler/handle-request
    (yada/handler
      (yada/resource
        {:methods {:get
                   {:produces "text/html"
                    :response (fn [ctx] {:from-resource :foo})}}}))
    req
    {}))

dominicm21:03:57

Required the extend-protocol above ^^

lsnape21:03:35

Thanks @dominicm . Iā€™ll try that out

dominicm21:03:16

Can't say I 100% understand why passing a fn directly works yet

dominicm21:03:32

Yep, it's matching on that. And (handler (fn [])) isn't what we want

dominicm21:03:01

Looking at the source for how protocols are implemented, it makes sense that functions match Object, even though isa? is false for fns.

dominicm21:03:24

So yeah, you need to implement functions for the protocol ^^ and then call handle-request correctly

dominicm21:03:27

Now I may sleep šŸ˜„

lsnape21:03:01

Ah yes that makes sense now. Works perfectly my end - thanks for your help! šŸ˜“