A Clojure library designed to provide very thin and simple interface layer between standard Liberator applications and Swagger with Spec support (via spec-tools
).
[liberator-swagger.core :refer [defresource swagger-routes make-swagger-object]
(defn app-routes
[{db :db]
(routes
(ANY "/users/:id" [] (users id db))
(ANY "/groups" [] (users db))
(swagger-routes {:swagger-object
(make-swagger-object
{:info {:version "0.0.1"
:title "Data Engine"
:description "Emergynt Data Engine API"}
:tags [{:name "tag1"
:description "First tag"}
{:name "tag 2"
:description "Second tag"}]
:paths {"/users" #'users
"/groups #'groups}})
:ui "/swagger"
:spec "/swagger.json"})
(route/resources "/")
(route/not-found "404")))
:swagger
metadata to defresource
like:(spec/def ::id uuid?)
(spec/def ::user some-user-definition)
(defresource users [id db]
{:swagger {:post {:tags ["tag1"]
:summary "Create new user"
::swagger/parameters {:path (spec/keys :req-un [::id])
:body ::user}
::swagger/responses {200 {:schema ::user}
:put {:tags ["tag1" "tag2"]
:summary "Update specific users"
::swagger/parameters {:path (spec/keys :req-un [::id])
:body ::user}
::swagger/responses {200 {:schema ::user}}}}
:allowed-methods [:post :put]
:available-media-types ["application/json"]
:post! (fn [ctx] (POST-CODE))
:put! (fn [ctx] (PUT-CODE)))
Copyright © 2019 FIXME
This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close