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