mirror of
https://github.com/metosin/reitit.git
synced 2025-12-18 08:51:12 +00:00
doc: remove examples/ring-swagger
... it's the same as ring-spec-swagger. Let's keep the pair ring-spec-swagger and ring-malli-swagger.
This commit is contained in:
parent
bcbdd05a6f
commit
bafc9b757f
10 changed files with 3 additions and 152 deletions
|
|
@ -143,7 +143,7 @@ Invalid request:
|
||||||
|
|
||||||
## More examples
|
## More examples
|
||||||
|
|
||||||
* [`reitit-ring` with coercion, swagger and default middleware](https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj)
|
* [`reitit-ring` with coercion, swagger and default middleware](https://github.com/metosin/reitit/blob/master/examples/ring-malli-swagger/src/example/server.clj)
|
||||||
* [`reitit-frontend`, the easy way](https://github.com/metosin/reitit/blob/master/examples/frontend/src/frontend/core.cljs)
|
* [`reitit-frontend`, the easy way](https://github.com/metosin/reitit/blob/master/examples/frontend/src/frontend/core.cljs)
|
||||||
* [`reitit-frontend` with Keechma-style controllers](https://github.com/metosin/reitit/blob/master/examples/frontend-controllers/src/frontend/core.cljs)
|
* [`reitit-frontend` with Keechma-style controllers](https://github.com/metosin/reitit/blob/master/examples/frontend-controllers/src/frontend/core.cljs)
|
||||||
* [`reitit-http` with Pedestal](https://github.com/metosin/reitit/blob/master/examples/pedestal/src/example/server.clj)
|
* [`reitit-http` with Pedestal](https://github.com/metosin/reitit/blob/master/examples/pedestal/src/example/server.clj)
|
||||||
|
|
|
||||||
|
|
@ -59,4 +59,4 @@ Partial sample output:
|
||||||
|
|
||||||
## Example app
|
## Example app
|
||||||
|
|
||||||
See an example app with the default middleware in action: https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj.
|
See an example app with the default middleware in action: <https://github.com/metosin/reitit/blob/master/examples/ring-malli-swagger/src/example/server.clj>.
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,7 @@ Another way to serve the swagger-ui is using the [default handler](default_handl
|
||||||
* missed routes are handled by `create-default-handler`
|
* missed routes are handled by `create-default-handler`
|
||||||
* served via [ring-jetty](https://github.com/ring-clojure/ring/tree/master/ring-jetty-adapter)
|
* served via [ring-jetty](https://github.com/ring-clojure/ring/tree/master/ring-jetty-adapter)
|
||||||
|
|
||||||
Whole example project is in [`/examples/ring-swagger`](https://github.com/metosin/reitit/tree/master/examples/ring-swagger).
|
Whole example project is in [`/examples/ring-spec-swagger`](https://github.com/metosin/reitit/tree/master/examples/ring-spec-swagger).
|
||||||
|
|
||||||
```clj
|
```clj
|
||||||
(ns example.server
|
(ns example.server
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,3 @@ Coercion with Malli and Swagger generation.
|
||||||
## ring-spec-swagger
|
## ring-spec-swagger
|
||||||
|
|
||||||
Coercion with Spec and Swagger generation.
|
Coercion with Spec and Swagger generation.
|
||||||
|
|
||||||
## ring-swagger
|
|
||||||
|
|
||||||
Coercion with Spec and Swagger generation. Same as previous!
|
|
||||||
|
|
|
||||||
11
examples/ring-swagger/.gitignore
vendored
11
examples/ring-swagger/.gitignore
vendored
|
|
@ -1,11 +0,0 @@
|
||||||
/target
|
|
||||||
/classes
|
|
||||||
/checkouts
|
|
||||||
pom.xml
|
|
||||||
pom.xml.asc
|
|
||||||
*.jar
|
|
||||||
*.class
|
|
||||||
/.lein-*
|
|
||||||
/.nrepl-port
|
|
||||||
.hgignore
|
|
||||||
.hg/
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
# Ring with Swagger example
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```clj
|
|
||||||
> lein repl
|
|
||||||
(start)
|
|
||||||
```
|
|
||||||
|
|
||||||
To test the endpoints using [httpie](https://httpie.org/):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
http GET :3000/math/plus x==1 y==20
|
|
||||||
http POST :3000/math/spec/plus x:=1 y:=20
|
|
||||||
|
|
||||||
http GET :3000/swagger.json
|
|
||||||
```
|
|
||||||
|
|
||||||
<img src="https://raw.githubusercontent.com/metosin/reitit/master/examples/ring-swagger/swagger.png" />
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Copyright © 2017-2018 Metosin Oy
|
|
||||||
|
|
@ -1,6 +0,0 @@
|
||||||
(defproject ring-example "0.1.0-SNAPSHOT"
|
|
||||||
:description "Reitit Ring App with Swagger"
|
|
||||||
:dependencies [[org.clojure/clojure "1.10.0"]
|
|
||||||
[ring/ring-jetty-adapter "1.7.1"]
|
|
||||||
[metosin/reitit "0.7.0-alpha1"]]
|
|
||||||
:repl-options {:init-ns example.server})
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 494 KiB |
|
|
@ -1,105 +0,0 @@
|
||||||
(ns example.server
|
|
||||||
(:require [reitit.ring :as ring]
|
|
||||||
[reitit.coercion.spec]
|
|
||||||
[reitit.swagger :as swagger]
|
|
||||||
[reitit.swagger-ui :as swagger-ui]
|
|
||||||
[reitit.ring.coercion :as coercion]
|
|
||||||
[reitit.dev.pretty :as pretty]
|
|
||||||
[reitit.ring.middleware.muuntaja :as muuntaja]
|
|
||||||
[reitit.ring.middleware.exception :as exception]
|
|
||||||
[reitit.ring.middleware.multipart :as multipart]
|
|
||||||
[reitit.ring.middleware.parameters :as parameters]
|
|
||||||
;; Uncomment to use
|
|
||||||
; [reitit.ring.middleware.dev :as dev]
|
|
||||||
[ring.adapter.jetty :as jetty]
|
|
||||||
[muuntaja.core :as m]
|
|
||||||
[clojure.java.io :as io]))
|
|
||||||
|
|
||||||
(def app
|
|
||||||
(ring/ring-handler
|
|
||||||
(ring/router
|
|
||||||
[["/swagger.json"
|
|
||||||
{:get {:no-doc true
|
|
||||||
:swagger {:info {:title "my-api"
|
|
||||||
:description "with reitit-ring"}}
|
|
||||||
:handler (swagger/create-swagger-handler)}}]
|
|
||||||
|
|
||||||
["/files"
|
|
||||||
{:swagger {:tags ["files"]}}
|
|
||||||
|
|
||||||
["/upload"
|
|
||||||
{:post {:summary "upload a file"
|
|
||||||
:parameters {:multipart {:file multipart/temp-file-part}}
|
|
||||||
:responses {200 {:body {:name string?, :size int?}}}
|
|
||||||
:handler (fn [{{{:keys [file]} :multipart} :parameters}]
|
|
||||||
{:status 200
|
|
||||||
:body {:name (:filename file)
|
|
||||||
:size (:size file)}})}}]
|
|
||||||
|
|
||||||
["/download"
|
|
||||||
{:get {:summary "downloads a file"
|
|
||||||
:swagger {:produces ["image/png"]}
|
|
||||||
:handler (fn [_]
|
|
||||||
{:status 200
|
|
||||||
:headers {"Content-Type" "image/png"}
|
|
||||||
:body (-> "reitit.png"
|
|
||||||
(io/resource)
|
|
||||||
(io/input-stream))})}}]]
|
|
||||||
|
|
||||||
["/math"
|
|
||||||
{:swagger {:tags ["math"]}}
|
|
||||||
|
|
||||||
["/plus"
|
|
||||||
{:get {:summary "plus with spec query parameters"
|
|
||||||
:parameters {:query {:x int?
|
|
||||||
:y int?}}
|
|
||||||
:responses {200 {:body {:total int?}}}
|
|
||||||
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
|
||||||
{:status 200
|
|
||||||
:body {:total (+ x y)}})}
|
|
||||||
:post {:summary "plus with spec body parameters"
|
|
||||||
:parameters {:body {:x int?
|
|
||||||
:y int?}}
|
|
||||||
:responses {200 {:body {:total int?}}}
|
|
||||||
:handler (fn [{{{:keys [x y]} :body} :parameters}]
|
|
||||||
{:status 200
|
|
||||||
:body {:total (+ x y)}})}}]]]
|
|
||||||
|
|
||||||
{;;:reitit.middleware/transform dev/print-request-diffs ;; pretty diffs
|
|
||||||
;;:validate spec/validate ;; enable spec validation for route data
|
|
||||||
;;:reitit.spec/wrap spell/closed ;; strict top-level validation
|
|
||||||
:exception pretty/exception
|
|
||||||
:data {:coercion reitit.coercion.spec/coercion
|
|
||||||
:muuntaja m/instance
|
|
||||||
:middleware [;; swagger feature
|
|
||||||
swagger/swagger-feature
|
|
||||||
;; query-params & form-params
|
|
||||||
parameters/parameters-middleware
|
|
||||||
;; content-negotiation
|
|
||||||
muuntaja/format-negotiate-middleware
|
|
||||||
;; encoding response body
|
|
||||||
muuntaja/format-response-middleware
|
|
||||||
;; exception handling
|
|
||||||
(exception/create-exception-middleware
|
|
||||||
{::exception/default (partial exception/wrap-log-to-console exception/default-handler)})
|
|
||||||
;; decoding request body
|
|
||||||
muuntaja/format-request-middleware
|
|
||||||
;; coercing response bodys
|
|
||||||
coercion/coerce-response-middleware
|
|
||||||
;; coercing request parameters
|
|
||||||
coercion/coerce-request-middleware
|
|
||||||
;; multipart
|
|
||||||
multipart/multipart-middleware]}})
|
|
||||||
(ring/routes
|
|
||||||
(swagger-ui/create-swagger-ui-handler
|
|
||||||
{:path "/"
|
|
||||||
:config {:validatorUrl nil
|
|
||||||
:operationsSorter "alpha"}})
|
|
||||||
(ring/create-default-handler))))
|
|
||||||
|
|
||||||
(defn start []
|
|
||||||
(jetty/run-jetty #'app {:port 3000, :join? false})
|
|
||||||
(println "server running in port 3000"))
|
|
||||||
|
|
||||||
(comment
|
|
||||||
(start))
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 228 KiB |
Loading…
Reference in a new issue