Fork me on GitHub
#ring-swagger
<
2017-05-09
>
ikitommi04:05:12

@mtkp you need to app the value of api (or the defoned var with defapi) into a ring-adapter (like http-kit) and start it. Here's an example: http://www.http-kit.org/server.html

ikitommi04:05:25

I think there should be a minimalistic reloaded repl -enabled template for c-api. Maybe with Mount to keep it newbie-friendly... or an example project at least.

csapp15:05:27

hey, new to compojure-api and swagger but trying to get it set up for my app. got it working yesterday (on 1.1.10) but now trying to add some token-based auth and not really sure what i'm doing. i've added :data {:securityDefinitions {:api_key {:type "apiKey" :name "token" :in "header"}} to my swagger map but not seeing any differences when i open up my swagger page. is there supposed to be a ui element added for me to add my api token to my headers somewhere? am i supposed to do something else?

csapp15:05:25

tried doing it through :header-params which works but it doesn't look like i can provide it for an entire context, only individual endpoints, and i don't want to add that boilerplate to every endpoint that requires auth

csapp15:05:15

to be clear: my auth works, i just want a way to still test my authenticated routes through swagger

kasuko18:05:09

Hey, I am using compojure-api for the data-driven resource style endpoints. However I can’t seem to figure out how to mark a query-param as optional. I have tried using s/maybe but that doesn’t seem to work. Any ideas?

ikitommi18:05:59

@kasuko you should use s/optional-key for it.

ikitommi18:05:02

(def handler
  (resource
    {:summary "increments query-param x, defaulting to 1"
     :parameters {:query-params {(s/optional-key :x) Long}}
     :responses {200 {:schema Long}}
     :handler (fn [request]
                (ok (-> request :query-params :x (or 0) inc)))}))

(handler {:request-method :get, :query-params {:x "41"}})
; {:status 200, :headers {}, :body 42, :compojure.api.meta/serializable? true}
(handler {:request-method :get, :query-params {}})
; {:status 200, :headers {}, :body 1, :compojure.api.meta/serializable? true}

kasuko18:05:31

ah I see, my bad I was trying to make the value optional but they key to the solution was the key 😛

ikitommi18:05:29

@csapp there should be a top-bar authentication link, which open a modal where you can enter the api-key

ikitommi18:05:39

also, you can mount authentication middleware at any level of your routing tree via the :middleware option. either to api (effects all routes), to context (bunch of routes) or to endpoint (just that one. You don’t have to add the :header-param, the top-level swagger :securityDefinitions should effect all. e.g. when it’s given via the ui, it’s passed to all requests.

ikitommi18:05:27

the actual enforcement of the api-key could be a middleware. Sadly, currently the basic-auth, token-auth & others are separate ring-libs, so you need to collect them together.

ikitommi18:05:00

If someone would have extra time, would like to see them prepackaged with compojure-api as they are commonly used.