This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-09
Channels
- # beginners (91)
- # boot (5)
- # cider (30)
- # clara (16)
- # cljsjs (3)
- # cljsrn (6)
- # clojure (84)
- # clojure-dev (4)
- # clojure-dusseldorf (1)
- # clojure-italy (15)
- # clojure-nl (2)
- # clojure-spec (5)
- # clojure-uk (120)
- # clojurescript (54)
- # core-async (25)
- # core-matrix (1)
- # css (2)
- # cursive (20)
- # datomic (28)
- # editors (11)
- # emacs (6)
- # figwheel (4)
- # figwheel-main (28)
- # fulcro (36)
- # graphql (7)
- # hyperfiddle (2)
- # jobs (6)
- # jobs-discuss (10)
- # lambdaisland (1)
- # lumo (3)
- # nrepl (20)
- # off-topic (24)
- # pedestal (2)
- # protorepl (3)
- # reagent (3)
- # reitit (2)
- # remote-jobs (1)
- # ring-swagger (26)
- # rum (1)
- # shadow-cljs (247)
- # spacemacs (29)
- # tools-deps (12)
- # vim (15)
I’ve gotten as far as understanding that you need to use schema to mark up the API endpoints and ring-swagger will generate an index.html
file to display the endpoints from the markup
I just want to make sure I’m not missing anything as I start to use ring-swagger day to day
(GET "/path/:x [x :as request] ....)
;;or
(GET "/path/:x" request
:path-params [x :- s/Int]
...)
great, thanks! Couple of questions..
Does the 2nd form enable swagger docs whilst the 1st doesn't?
Do both of those work with compojure.api.sweet/resource
?
the normal compojure syntax (1st) doesn't contribute to swagger docs. The latter does (as it's c-api addon).
in resource
, the :handler
is just a function of request => response, so no special syntax involved
@alexkeyes to use swagger, you just need to generate a valid swagger.json. ring-swagger helps if you are using Schema already, e.g. it does Schema => Swagger conversion. For clojure.spec, spec-tools library will help.
so just to clarify, what does the generation of the swagger.json
file? compojure-api (if I decide to use it?)
I mean to say I’m at the point where I understand what swagger is and what it needs to work, I just haven’t grokked how we can take clojure code and make it understand an API
in compojure-api, there is a ring handler api
, which takes options map and the compojure(-api) routes. It creates the ring-swagger data based on the routes and puts the data into request for the swagger-handler to use at runtime.
(require '[compojure.api.sweet :refer :all])
(require '[ring.util.http-response :refer :all])
(def app
(api
{:swagger
{:ui "/api-docs"
:spec "/swagger.json"}}
(GET "/hello" []
(ok {:message "hello"})}))))
api
is a function. which return a ring handler. when it’s evaluated, it creates the swagger-data once. c-api has no extra macros, besides the ones from compojure.