mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 00:41:12 +00:00
doc: openapi3 in examples/ring-malli-swagger
This commit is contained in:
parent
b5c9ee274d
commit
224acf930e
3 changed files with 23 additions and 4 deletions
|
|
@ -7,6 +7,10 @@
|
|||
(start)
|
||||
```
|
||||
|
||||
- Swagger spec served at <http://localhost:3000/swagger.json>
|
||||
- Openapi spec served at <http://localhost:3000/openapi.json>
|
||||
- Swagger UI served at <http://localhost:3000/>
|
||||
|
||||
To test the endpoints using [httpie](https://httpie.org/):
|
||||
|
||||
```bash
|
||||
|
|
@ -20,4 +24,4 @@ http GET :3000/swagger.json
|
|||
|
||||
## License
|
||||
|
||||
Copyright © 2017-2019 Metosin Oy
|
||||
Copyright © 2017-2023 Metosin Oy
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
:dependencies [[org.clojure/clojure "1.10.0"]
|
||||
[metosin/jsonista "0.2.6"]
|
||||
[ring/ring-jetty-adapter "1.7.1"]
|
||||
[metosin/reitit "0.6.0"]]
|
||||
[metosin/reitit "0.6.0"]
|
||||
[metosin/ring-swagger-ui "5.0.0-alpha.0"]]
|
||||
:repl-options {:init-ns example.server}
|
||||
:profiles {:dev {:dependencies [[ring/ring-mock "0.3.2"]]}})
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
(ns example.server
|
||||
(:require [reitit.ring :as ring]
|
||||
[reitit.coercion.malli]
|
||||
[reitit.openapi :as openapi]
|
||||
[reitit.ring.malli]
|
||||
[reitit.swagger :as swagger]
|
||||
[reitit.swagger-ui :as swagger-ui]
|
||||
|
|
@ -24,10 +25,17 @@
|
|||
[["/swagger.json"
|
||||
{:get {:no-doc true
|
||||
:swagger {:info {:title "my-api"
|
||||
:description "with [malli](https://github.com/metosin/malli) and reitit-ring"}
|
||||
:description "swagger docs with [malli](https://github.com/metosin/malli) and reitit-ring"
|
||||
:version "0.0.1"}
|
||||
:tags [{:name "files", :description "file api"}
|
||||
{:name "math", :description "math api"}]}
|
||||
:handler (swagger/create-swagger-handler)}}]
|
||||
["/openapi.json"
|
||||
{:get {:no-doc true
|
||||
:openapi {:info {:title "my-api"
|
||||
:description "openapi3 docs with [malli](https://github.com/metosin/malli) and reitit-ring"
|
||||
:version "0.0.1"}}
|
||||
:handler (openapi/create-openapi-handler)}}]
|
||||
|
||||
["/files"
|
||||
{:swagger {:tags ["files"]}}
|
||||
|
|
@ -44,6 +52,8 @@
|
|||
["/download"
|
||||
{:get {:summary "downloads a file"
|
||||
:swagger {:produces ["image/png"]}
|
||||
:responses {200 {:description "an image"
|
||||
:content {"image/png" any?}}}
|
||||
:handler (fn [_]
|
||||
{:status 200
|
||||
:headers {"Content-Type" "image/png"}
|
||||
|
|
@ -96,8 +106,9 @@
|
|||
;; malli options
|
||||
:options nil})
|
||||
:muuntaja m/instance
|
||||
:middleware [;; swagger feature
|
||||
:middleware [;; swagger & openapi
|
||||
swagger/swagger-feature
|
||||
openapi/openapi-feature
|
||||
;; query-params & form-params
|
||||
parameters/parameters-middleware
|
||||
;; content-negotiation
|
||||
|
|
@ -118,6 +129,9 @@
|
|||
(swagger-ui/create-swagger-ui-handler
|
||||
{:path "/"
|
||||
:config {:validatorUrl nil
|
||||
:urls [{:name "swagger", :url "swagger.json"}
|
||||
{:name "openapi", :url "openapi.json"}]
|
||||
:urls.primaryName "openapi"
|
||||
:operationsSorter "alpha"}})
|
||||
(ring/create-default-handler))))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue