This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-13
Channels
- # beginners (78)
- # boot (27)
- # cider (13)
- # cljs-dev (41)
- # cljsrn (4)
- # clojure (216)
- # clojure-android (1)
- # clojure-conj (6)
- # clojure-greece (1)
- # clojure-italy (11)
- # clojure-russia (127)
- # clojure-spec (63)
- # clojure-uk (34)
- # clojurescript (68)
- # core-async (5)
- # cursive (5)
- # data-science (1)
- # datomic (4)
- # dirac (11)
- # editors (7)
- # events (1)
- # graphql (12)
- # hoplon (39)
- # jobs (1)
- # liberator (3)
- # lumo (101)
- # off-topic (14)
- # om (3)
- # onyx (3)
- # parinfer (14)
- # re-frame (10)
- # reagent (2)
- # remote-jobs (1)
- # ring-swagger (17)
- # sql (21)
- # untangled (38)
- # vim (3)
- # yada (23)
for those, who want to test the latest - 2.0.0-alpha2 is out. Many small fixes + the spec coercion support: https://github.com/metosin/compojure-api/blob/master/CHANGELOG.md#200-alpha2-1362017
the new coercion guide, here: https://github.com/metosin/compojure-api/wiki/Coercion
supports both vanilla specs & data-specs. the latter feels like Schema:
(def app
(api
{:coercion :spec}
(context "/math/:a" []
;; path-parameter should be a number
:path-params [a :- spec/int?]
(POST "/plus" []
;; query-parameters should be numbers, `c` defaults to 0
:query-params [b :- spec/int?, {c :- spec/int? 0}]
;; body should be a map with a `:d` number
:body [numbers {:d spec/int?}]
;; response for 200 should be a map with `:total` number
:return {:total ::total}
;; input is already coerced here.
(ok {:total (+ a b c (:d numbers))})))
(context "/data-math" []
(resource
;; to make coercion explicit
{:coercion :spec
:get {:parameters {:query-params {:x spec/int?, :y spec/int?}}
:responses {200 {:schema ::total-body}}
:handler (fn [{{:keys [x y]} :query-params}]
(ok {:total (+ x y)}))}}))))
(-> {:request-method :get
:uri "/data-math"
:query-params {:x "1", :y "2"}}
(app)
:body
(slurp)
(cheshire.core/parse-string true))
; {:total 3}
@ikitommi hey, is there a way convenient to wrap swagger url with middleware? for example say, if you wanted your api-docs to be accessible from only one ip
@ikitommi, im testing the new alpha, but im unable to start the server
Exception in thread "main" java.io.FileNotFoundException: Could not locate compojure/api/request__init.class or compojure/api/request.clj on classpath., compiling:(compojure/api/coercion/schema.clj:1:1)
at clojure.lang.Compiler.load(Compiler.java:7391)
at clojure.lang.RT.loadResourceScript(RT.java:372)
......
do i need to do anything else besides updating the deps to [metosin/compojure-api "2.0.0-alpha2"]
?Huh, for some reason compojure.api.request
ns is in test
folder
Except for cloning the repo and fixing this no, test files are not included in jar so new release is needed
Has anyone tried out the new alpha with swagger? I wasn't able to get the body and query params to show up as an option on the example for /math/:a/plus. The output in my swagger json is
"/math/{a}/plus":{
"post":{
"parameters":[
{
"in":"path",
"name":"a",
"description":"",
"required":true,
"type":"string"
}
],