Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/swagger toplevel description #268

Merged
merged 4 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions doc/swagger.org
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
You need to specify your swagger.json and swagger-ui endpoints at the config file
#+begin_src clojure
:xiana/swagger {:uri-path "/swagger/swagger.json"
:path :swagger.json
:data {:coercion (reitit.coercion.malli/create
{:error-keys #{:coercion :in :schema :value :errors :humanized}
:compile malli.util/closed-schema
:strip-extra-keys true
:default-values true
:options nil})
:middleware [reitit.swagger/swagger-feature]}}
:path :swagger.json
:data {:coercion (reitit.coercion.malli/create
{:error-keys #{:coercion :in :schema :value :errors :humanized}
:compile malli.util/closed-schema
:strip-extra-keys true
:default-values true
:options nil})
:middleware [reitit.swagger/swagger-feature]
;;; This is toplevel info for your project swagger-ui page
:info {:title "Your Project Title goes HERE"
:description "Some description"
:version "0.1"}}}

:xiana/swagger-ui {:uri-path "/swagger/swagger-ui"}
#+end_src

Expand All @@ -36,7 +41,7 @@ the *routes/reset*
If you want a description for your endpoint on the *swagger-ui* page, include it in your route in the map
associated with the swagger key as below:
#+begin_src clojure
["/users" {:get {:swagger {:description "User get endpoint"}
["/users" {:get {:description "This is the description that will appear on swagger-ui under this endpoint"
:action #'users/get-all-users}}]
#+end_src

Expand All @@ -49,11 +54,11 @@ you already have a malli schema for your endpoint, you can reuse that.
At the moment *xiana.swagger* will ONLY work with malli schemas!

#+begin_src clojure

["/users" {:post {:action #'users/add-users
:schema UsersAddReqPayload
:parameters {:body UsersAddReqPayload}
:swagger {:description "User post endpoint"}}}]
:description "This is the description that will appear on swagger-ui under this endpoint"}}]

#+end_src

If you don't already use a schema you can specify it inline like this:
Expand All @@ -63,5 +68,5 @@ If you don't already use a schema you can specify it inline like this:
:parameters {:body [:map {:closed true}
[:name string?]
[:age int?]]}
:swagger {:description "User post endpoint"}}}]
:description "This is the description that will appear on swagger-ui under this endpoint"}}]
#+end_src
6 changes: 3 additions & 3 deletions src/xiana/swagger.clj
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
(if (get acc method)
(if (get-in acc [method :handler])
acc
(-> acc
(assoc-in [method :handler] identity)))
(assoc-in acc [method :handler] identity))
acc))
opt-map
all-methods))
Expand Down Expand Up @@ -118,7 +117,8 @@
[routes & {route-opt-map :route-opt-map}]
(let [router (ring/router routes (or route-opt-map {}))
swagger {:swagger "2.0"
:x-id ::default}
:x-id ::default
:info (get-in route-opt-map [:data :info])}
map-in-order #(->> % (apply concat) (apply array-map))
paths (->> router
(r/compiled-routes)
Expand Down
Loading