Update swagger-guide, fixes #180

This commit is contained in:
Tommi Reiman 2018-12-09 20:16:32 +02:00
parent d21ec8d490
commit 147034d914

View file

@ -69,7 +69,7 @@ Webjars also hosts a [version](https://github.com/webjars/swagger-ui) of the swa
* two routes * two routes
* swagger-spec served from `"/swagger.json"` * swagger-spec served from `"/swagger.json"`
* swagger-ui mounted to `"/"` * swagger-ui mounted to `"/api-docs"`
* note that for real-world use, you need a [content-negation middleware][muuntaja] - * note that for real-world use, you need a [content-negation middleware][muuntaja] -
see the next example see the next example
@ -86,10 +86,9 @@ Webjars also hosts a [version](https://github.com/webjars/swagger-ui) of the swa
[["/api" [["/api"
["/ping" {:get (constantly {:status 200, :body "ping"})}] ["/ping" {:get (constantly {:status 200, :body "ping"})}]
["/pong" {:post (constantly {:status 200, :body "pong"})}]] ["/pong" {:post (constantly {:status 200, :body "pong"})}]]
["/swagger.json" ["" {:no-doc true}
{:get {:no-doc true ["/swagger.json" {:get (swagger/create-swagger-handler)}]
:handler (swagger/create-swagger-handler)}}]]) ["/api-docs/*" {:get (swagger-ui/create-swagger-ui-handler)}]]])))
(swagger-ui/create-swagger-ui-handler {:path "/"})))
``` ```
The generated swagger spec: The generated swagger spec:
@ -106,10 +105,27 @@ The generated swagger spec:
Swagger-ui: Swagger-ui:
```clj ```clj
(app {:request-method :get :uri "/"}) (app {:request-method :get, :uri "/api-docs/index.html"})
; ... the swagger-ui index-page, configured correctly ; ... the swagger-ui index-page, configured correctly
``` ```
You might be interested in adding a [trailing slash handler](slash_handler.md) to the app to serve the swagger-ui from `/api-docs` (without the trailing slash) too.
Another way to serve the swagger-ui is using the [default handler](default_handler.md):
```clj
(def app
(ring/ring-handler
(ring/router
[["/api"
["/ping" {:get (constantly {:status 200, :body "ping"})}]
["/pong" {:post (constantly {:status 200, :body "pong"})}]]
["/swagger.json"
{:get {:no-doc true
:handler (swagger/create-swagger-handler)}}]])
(swagger-ui/create-swagger-ui-handler {:path "/api-docs"})))
```
### More complete example ### More complete example
* `clojure.spec` coercion * `clojure.spec` coercion