mirror of
https://github.com/metosin/reitit.git
synced 2025-12-16 16:01:11 +00:00
Merge pull request #481 from metosin/swagger-param-description-examples
Swagger param description examples
This commit is contained in:
commit
a7f3cd15ab
6 changed files with 83 additions and 14 deletions
50
examples/README.md
Normal file
50
examples/README.md
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# Examples
|
||||
|
||||
## buddy-auth
|
||||
## frontend-auth
|
||||
## frontend-controllers
|
||||
## frontend-links
|
||||
## frontend-prompt
|
||||
## frontend-re-frame
|
||||
## frontend
|
||||
## http-swagger
|
||||
|
||||
Coercion with Spec and Swagger generation.
|
||||
|
||||
Same as ring-spec-swagger?
|
||||
|
||||
Async examples as extra.
|
||||
|
||||
## http
|
||||
|
||||
Async example.
|
||||
|
||||
## just-coercion-with-ring
|
||||
|
||||
Bad name.
|
||||
|
||||
Coercion example for spec, data-spec, Schema.
|
||||
No Swagger generation or Malli!
|
||||
|
||||
Same as ring-example?
|
||||
|
||||
## pedestal-swagger
|
||||
## pedestal
|
||||
## ring-example
|
||||
|
||||
Coercion example for spec, data-spec, Schema.
|
||||
No Swagger generation or Malli!
|
||||
|
||||
## ring-integrant
|
||||
|
||||
## ring-malli-swagger
|
||||
|
||||
Coercion with Malli and Swagger generation.
|
||||
|
||||
## ring-spec-swagger
|
||||
|
||||
Coercion with Spec and Swagger generation.
|
||||
|
||||
## ring-swagger
|
||||
|
||||
Coercion with Spec and Swagger generation. Same as previous!
|
||||
|
|
@ -56,13 +56,25 @@
|
|||
|
||||
["/plus"
|
||||
{:get {:summary "plus with malli query parameters"
|
||||
:parameters {:query [:map [:x int?] [:y int?]]}
|
||||
:parameters {:query [:map
|
||||
[:x
|
||||
{:title "X parameter"
|
||||
:description "Description for X parameter"
|
||||
:json-schema/default 42}
|
||||
int?]
|
||||
[:y int?]]}
|
||||
:responses {200 {:body [:map [:total int?]]}}
|
||||
:handler (fn [{{{:keys [x y]} :query} :parameters}]
|
||||
{:status 200
|
||||
:body {:total (+ x y)}})}
|
||||
:post {:summary "plus with malli body parameters"
|
||||
:parameters {:body [:map [:x int?] [:y int?]]}
|
||||
:parameters {:body [:map
|
||||
[:x
|
||||
{:title "X parameter"
|
||||
:description "Description for X parameter"
|
||||
:json-schema/default 42}
|
||||
int?]
|
||||
[:y int?]]}
|
||||
:responses {200 {:body [:map [:total int?]]}}
|
||||
:handler (fn [{{{:keys [x y]} :body} :parameters}]
|
||||
{:status 200
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
; [reitit.ring.middleware.dev :as dev]
|
||||
; [reitit.ring.spec :as spec]
|
||||
; [spec-tools.spell :as spell]
|
||||
[spec-tools.core :as st]
|
||||
[ring.adapter.jetty :as jetty]
|
||||
[muuntaja.core :as m]
|
||||
[clojure.spec.alpha :as s]
|
||||
|
|
@ -25,7 +26,12 @@
|
|||
(s/def ::size int?)
|
||||
(s/def ::file-response (s/keys :req-un [::name ::size]))
|
||||
|
||||
(s/def ::x int?)
|
||||
;; Use data-specs to provide extra JSON-Schema properties:
|
||||
;; https://github.com/metosin/spec-tools/blob/master/docs/04_json_schema.md#annotated-specs
|
||||
(s/def ::x (st/spec {:spec int?
|
||||
:name "X parameter"
|
||||
:description "Description for X parameter"
|
||||
:json-schema/default 42}))
|
||||
(s/def ::y int?)
|
||||
(s/def ::total int?)
|
||||
(s/def ::math-request (s/keys :req-un [::x ::y]))
|
||||
|
|
|
|||
|
|
@ -11,8 +11,6 @@
|
|||
[reitit.ring.middleware.parameters :as parameters]
|
||||
;; Uncomment to use
|
||||
; [reitit.ring.middleware.dev :as dev]
|
||||
; [reitit.ring.spec :as spec]
|
||||
; [spec-tools.spell :as spell]
|
||||
[ring.adapter.jetty :as jetty]
|
||||
[muuntaja.core :as m]
|
||||
[clojure.java.io :as io]))
|
||||
|
|
@ -53,13 +51,15 @@
|
|||
|
||||
["/plus"
|
||||
{:get {:summary "plus with spec query parameters"
|
||||
:parameters {:query {:x int?, :y int?}}
|
||||
: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?}}
|
||||
:parameters {:body {:x int?
|
||||
:y int?}}
|
||||
:responses {200 {:body {:total int?}}}
|
||||
:handler (fn [{{{:keys [x y]} :body} :parameters}]
|
||||
{:status 200
|
||||
|
|
@ -80,7 +80,8 @@
|
|||
;; encoding response body
|
||||
muuntaja/format-response-middleware
|
||||
;; exception handling
|
||||
exception/exception-middleware
|
||||
(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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str])
|
||||
(:import (java.time Instant)
|
||||
(java.io PrintWriter)))
|
||||
(java.io PrintWriter Writer)))
|
||||
|
||||
(s/def ::handlers (s/map-of any? fn?))
|
||||
(s/def ::spec (s/keys :opt-un [::handlers]))
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
(wrap error-handler error request)
|
||||
(error-handler error request))))
|
||||
|
||||
(defn print! [^PrintWriter writer & more]
|
||||
(defn print! [^Writer writer & more]
|
||||
(.write writer (str (str/join " " more) "\n")))
|
||||
|
||||
;;
|
||||
|
|
@ -68,7 +68,7 @@
|
|||
|
||||
(defn wrap-log-to-console [handler ^Throwable e {:keys [uri request-method] :as req}]
|
||||
(print! *out* (Instant/now) request-method (pr-str uri) "=>" (.getMessage e))
|
||||
(.printStackTrace e ^PrintWriter *out*)
|
||||
(.printStackTrace e (PrintWriter. ^Writer *out*))
|
||||
(handler e req))
|
||||
|
||||
;;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str])
|
||||
(:import (java.time Instant)
|
||||
(java.io PrintWriter)))
|
||||
(java.io Writer PrintWriter)))
|
||||
|
||||
(s/def ::handlers (s/map-of any? fn?))
|
||||
(s/def ::spec (s/keys :opt-un [::handlers]))
|
||||
|
|
@ -55,7 +55,7 @@
|
|||
(catch Throwable e
|
||||
(on-exception handlers e request respond raise)))))))
|
||||
|
||||
(defn print! [^PrintWriter writer & more]
|
||||
(defn print! [^Writer writer & more]
|
||||
(.write writer (str (str/join " " more) "\n")))
|
||||
|
||||
;;
|
||||
|
|
@ -88,7 +88,7 @@
|
|||
|
||||
(defn wrap-log-to-console [handler ^Throwable e {:keys [uri request-method] :as req}]
|
||||
(print! *out* (Instant/now) request-method (pr-str uri) "=>" (.getMessage e))
|
||||
(.printStackTrace e ^PrintWriter *out*)
|
||||
(.printStackTrace e (PrintWriter. ^Writer *out*))
|
||||
(handler e req))
|
||||
|
||||
;;
|
||||
|
|
|
|||
Loading…
Reference in a new issue