Merge pull request #569 from SagaHealthcareIT/swagger-operationid-support

Swagger: support operationId in generated swagger json
This commit is contained in:
Tommi Reiman 2023-01-09 17:14:10 +02:00 committed by GitHub
commit af441e6154
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,11 +10,12 @@
(s/def ::id (s/or :keyword keyword? :set (s/coll-of keyword? :into #{}))) (s/def ::id (s/or :keyword keyword? :set (s/coll-of keyword? :into #{})))
(s/def ::no-doc boolean?) (s/def ::no-doc boolean?)
(s/def ::tags (s/coll-of (s/or :keyword keyword? :string string?) :kind #{})) (s/def ::tags (s/coll-of (s/or :keyword keyword? :string string?) :kind #{}))
(s/def ::operationId string?)
(s/def ::summary string?) (s/def ::summary string?)
(s/def ::description string?) (s/def ::description string?)
(s/def ::swagger (s/keys :opt-un [::id])) (s/def ::swagger (s/keys :opt-un [::id]))
(s/def ::spec (s/keys :opt-un [::swagger ::no-doc ::tags ::summary ::description])) (s/def ::spec (s/keys :opt-un [::swagger ::no-doc ::tags ::operationId ::summary ::description]))
(def swagger-feature (def swagger-feature
"Feature for handling swagger-documentation for routes. "Feature for handling swagger-documentation for routes.
@ -52,6 +53,7 @@
[\"/plus\" [\"/plus\"
{:get {:swagger {:tags \"math\"} {:get {:swagger {:tags \"math\"}
:operationId \"addTwoNumbers\"
:summary \"adds numbers together\" :summary \"adds numbers together\"
:description \"takes `x` and `y` query-params and adds them together\" :description \"takes `x` and `y` query-params and adds them together\"
:parameters {:query {:x int?, :y int?}} :parameters {:query {:x int?, :y int?}}
@ -75,7 +77,7 @@
(let [{:keys [id] :or {id ::default} :as swagger} (-> match :result request-method :data :swagger) (let [{:keys [id] :or {id ::default} :as swagger} (-> match :result request-method :data :swagger)
ids (trie/into-set id) ids (trie/into-set id)
strip-top-level-keys #(dissoc % :id :info :host :basePath :definitions :securityDefinitions) strip-top-level-keys #(dissoc % :id :info :host :basePath :definitions :securityDefinitions)
strip-endpoint-keys #(dissoc % :id :parameters :responses :summary :description) strip-endpoint-keys #(dissoc % :id :operationId :parameters :responses :summary :description)
swagger (->> (strip-endpoint-keys swagger) swagger (->> (strip-endpoint-keys swagger)
(merge {:swagger "2.0" (merge {:swagger "2.0"
:x-id ids})) :x-id ids}))
@ -93,7 +95,7 @@
(apply meta-merge (keep (comp :swagger :data) interceptors)) (apply meta-merge (keep (comp :swagger :data) interceptors))
(if coercion (if coercion
(coercion/get-apidocs coercion :swagger data)) (coercion/get-apidocs coercion :swagger data))
(select-keys data [:tags :summary :description]) (select-keys data [:tags :operationId :summary :description])
(strip-top-level-keys swagger))])) (strip-top-level-keys swagger))]))
transform-path (fn [[p _ c]] transform-path (fn [[p _ c]]
(if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))] (if-let [endpoint (some->> c (keep transform-endpoint) (seq) (into {}))]