Fix swaggr-example

This commit is contained in:
Tommi Reiman 2018-04-29 15:18:30 +03:00
parent 30274bf961
commit c3726aeb5d
3 changed files with 12 additions and 12 deletions

View file

@ -1,17 +1,10 @@
# WIP: Ring + Swagger example
TODO:
* Serve Swagger-ui.
## Usage
```clj
> lein repl
(require '[example.server :as server])
(server/start)
(start)
```
To test the endpoints using [httpie](https://httpie.org/):
@ -23,6 +16,9 @@ http GET :3000/api/spec/plus x==1 y==20
http GET :3000/api/swagger.json
```
* swagger.json: http://localhost:3000/api/swagger.json
* swagger-ui: http://localhost:3000/api-docs/index.html
## License
Copyright © 2017 Metosin Oy

View file

@ -3,5 +3,6 @@
:dependencies [[org.clojure/clojure "1.9.0"]
[ring "1.6.3"]
[metosin/muuntaja "0.5.0"]
[org.webjars/swagger-ui "3.13.6"]
[metosin/reitit "0.1.1-SNAPSHOT"]]
:repl-options {:init-ns example.server})

View file

@ -19,7 +19,7 @@
["/swagger.json"
{:get {:no-doc true
:swagger {:info {:title "my-api"}}
:handler swagger/swagger-spec-handler}}]
:handler (swagger/create-swagger-handler)}}]
["/spec" {:coercion spec/coercion}
["/plus"
@ -37,9 +37,10 @@
:handler (fn [{{{:keys [x y]} :query} :parameters}]
{:status 200, :body {:total (+ x y)}})}}]]]
;; serve api-docs here
["/api-docs/*"
(constantly {:status 200, :body "api-docs"})]]
{:no-doc true
:handler (ring/create-resource-handler
{:root "META-INF/resources/webjars/swagger-ui/3.13.6"})}]]
{:data {:middleware [ring.middleware.params/wrap-params
muuntaja.middleware/wrap-format
@ -47,7 +48,9 @@
rrc/coerce-exceptions-middleware
rrc/coerce-request-middleware
rrc/coerce-response-middleware]}})
(ring/create-default-handler)))
(ring/routes
(ring/create-resource-handler {:path "/"})
(ring/create-default-handler))))
(defn start []
(jetty/run-jetty #'app {:port 3000, :join? false})