mirror of
https://github.com/metosin/reitit.git
synced 2026-02-25 18:42:24 +00:00
Merge pull request #452 from TimoKramer/support-operationid
Support operationId in reitit-swagger
This commit is contained in:
commit
8087522b82
3 changed files with 43 additions and 36 deletions
|
|
@ -23,6 +23,7 @@ The following route data keys contribute to the generated swagger specification:
|
|||
| :tags | optional set of string or keyword tags for an endpoint api docs
|
||||
| :summary | optional short string summary of an endpoint
|
||||
| :description | optional long description of an endpoint. Supports http://spec.commonmark.org/
|
||||
| :operationId | optional string specifying the unique ID of an Operation
|
||||
|
||||
Coercion keys also contribute to the docs:
|
||||
|
||||
|
|
|
|||
|
|
@ -13,9 +13,10 @@
|
|||
(s/def ::operationId string?)
|
||||
(s/def ::summary string?)
|
||||
(s/def ::description string?)
|
||||
(s/def ::operationId string?)
|
||||
|
||||
(s/def ::swagger (s/keys :opt-un [::id]))
|
||||
(s/def ::spec (s/keys :opt-un [::swagger ::no-doc ::tags ::operationId ::summary ::description]))
|
||||
(s/def ::spec (s/keys :opt-un [::swagger ::no-doc ::tags ::summary ::description ::operationId]))
|
||||
|
||||
(def swagger-feature
|
||||
"Feature for handling swagger-documentation for routes.
|
||||
|
|
@ -77,7 +78,7 @@
|
|||
(let [{:keys [id] :or {id ::default} :as swagger} (-> match :result request-method :data :swagger)
|
||||
ids (trie/into-set id)
|
||||
strip-top-level-keys #(dissoc % :id :info :host :basePath :definitions :securityDefinitions)
|
||||
strip-endpoint-keys #(dissoc % :id :operationId :parameters :responses :summary :description)
|
||||
strip-endpoint-keys #(dissoc % :id :parameters :responses :summary :description :operationId)
|
||||
swagger (->> (strip-endpoint-keys swagger)
|
||||
(merge {:swagger "2.0"
|
||||
:x-id ids}))
|
||||
|
|
@ -95,7 +96,7 @@
|
|||
(apply meta-merge (keep (comp :swagger :data) interceptors))
|
||||
(if coercion
|
||||
(coercion/get-apidocs coercion :swagger data))
|
||||
(select-keys data [:tags :operationId :summary :description])
|
||||
(select-keys data [:tags :summary :description :operationId])
|
||||
(strip-top-level-keys swagger))]))
|
||||
transform-path (fn [[p _ c]]
|
||||
(if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))]
|
||||
|
|
|
|||
|
|
@ -25,11 +25,13 @@
|
|||
["/spec" {:coercion spec/coercion}
|
||||
["/plus/:z"
|
||||
{:patch {:summary "patch"
|
||||
:operationId "Patch"
|
||||
:handler (constantly {:status 200})}
|
||||
:options {:summary "options"
|
||||
:middleware [{:data {:swagger {:responses {200 {:description "200"}}}}}]
|
||||
:handler (constantly {:status 200})}
|
||||
:get {:summary "plus"
|
||||
:operationId "GetPlus"
|
||||
:parameters {:query {:x int?, :y int?}
|
||||
:path {:z int?}}
|
||||
:swagger {:responses {400 {:schema {:type "string"}
|
||||
|
|
@ -118,6 +120,7 @@
|
|||
(app {:request-method :get
|
||||
:uri "/api/schema/plus/3"
|
||||
:query-params {:x "2", :y "1"}})))))
|
||||
|
||||
(testing "swagger-spec"
|
||||
(let [spec (:body (app {:request-method :get
|
||||
:uri "/api/swagger.json"}))
|
||||
|
|
@ -126,6 +129,7 @@
|
|||
:info {:title "my-api"}
|
||||
:paths {"/api/spec/plus/{z}" {:patch {:parameters []
|
||||
:summary "patch"
|
||||
:operationId "Patch"
|
||||
:responses {:default {:description ""}}}
|
||||
:options {:parameters []
|
||||
:summary "options"
|
||||
|
|
@ -156,7 +160,8 @@
|
|||
400 {:schema {:type "string"}
|
||||
:description "kosh"}
|
||||
500 {:description "fail"}}
|
||||
:summary "plus"}
|
||||
:summary "plus"
|
||||
:operationId "GetPlus"}
|
||||
:post {:parameters [{:in "body",
|
||||
:name "body",
|
||||
:description "",
|
||||
|
|
|
|||
Loading…
Reference in a new issue