From 224acf930e79f915905c9a00e9f5380b8319c233 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Thu, 16 Mar 2023 10:05:23 +0200 Subject: [PATCH] doc: openapi3 in examples/ring-malli-swagger --- examples/ring-malli-swagger/README.md | 6 +++++- examples/ring-malli-swagger/project.clj | 3 ++- .../ring-malli-swagger/src/example/server.clj | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/examples/ring-malli-swagger/README.md b/examples/ring-malli-swagger/README.md index 3a2144c2..6162591b 100644 --- a/examples/ring-malli-swagger/README.md +++ b/examples/ring-malli-swagger/README.md @@ -7,6 +7,10 @@ (start) ``` +- Swagger spec served at +- Openapi spec served at +- Swagger UI served at + 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 diff --git a/examples/ring-malli-swagger/project.clj b/examples/ring-malli-swagger/project.clj index 406e05c6..a2991dae 100644 --- a/examples/ring-malli-swagger/project.clj +++ b/examples/ring-malli-swagger/project.clj @@ -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"]]}}) diff --git a/examples/ring-malli-swagger/src/example/server.clj b/examples/ring-malli-swagger/src/example/server.clj index bc9c3861..1b3d880d 100644 --- a/examples/ring-malli-swagger/src/example/server.clj +++ b/examples/ring-malli-swagger/src/example/server.clj @@ -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))))