mirror of
https://github.com/metosin/reitit.git
synced 2025-12-25 11:18:25 +00:00
Add examples for Swagger parameter description
This commit is contained in:
parent
349c838de4
commit
8a205002a8
3 changed files with 30 additions and 7 deletions
|
|
@ -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.data-spec :as ds]
|
||||
[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 (ds/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,7 @@
|
|||
[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]
|
||||
[schema-tools.core :as st]
|
||||
[ring.adapter.jetty :as jetty]
|
||||
[muuntaja.core :as m]
|
||||
[clojure.java.io :as io]))
|
||||
|
|
@ -53,13 +52,19 @@
|
|||
|
||||
["/plus"
|
||||
{:get {:summary "plus with spec query parameters"
|
||||
:parameters {:query {:x int?, :y int?}}
|
||||
:parameters {:query {:x (st/schema int? {:title "X parameter"
|
||||
:description "Description for X parameter"
|
||||
:json-schema/default 42})
|
||||
: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? #_(st/schema int? {:name "X parameter"
|
||||
:description "Description for X parameter"
|
||||
:json-schema/default 42})
|
||||
:y int?}}
|
||||
:responses {200 {:body {:total int?}}}
|
||||
:handler (fn [{{{:keys [x y]} :body} :parameters}]
|
||||
{:status 200
|
||||
|
|
|
|||
Loading…
Reference in a new issue