Sweet web apis with Compojure & Swagger
(defn more-routes [db version]
(routes
(GET "/version" []
(ok {:version version}))
(POST "/thingie" []
(ok (thingie/create db)))))
(defn app [db]
(api
(context "/api/:version" []
:path-params [version :- s/Str]
(more-routes db version)
(GET "/kikka" []
(ok "kukka")))))
Routing
protocol. They can still be used for handling request, just without docs.
[:api :invalid-routes-fn]
to declare how to handle routes not satisfying
the Routing
protocol. Default implementation logs invalid routes as WARNINGs.compojure.api.sweet
:
let-request
, routing
, wrap-routes
*
) is removed from route macro & function names, as there is no reason to mix compojure-api & compojure route macros.
GET*
=> GET
ANY*
=> ANY
HEAD*
=> HEAD
PATCH*
=> PATCH
DELETE*
=> DELETE
OPTIONS*
=> OPTIONS
POST*
=> PUT
context*
=> context
defroutes*
=> defroutes
swagger-docs
and swagger-ui
are now longer in compojure.api.sweet
:swagger
(has no defaults)swagger-routes
function, mounting both the swagger-ui
and swagger-docs
and wiring them together
/
and the swagger-spec to /swagger.json
swagger-ui
& swagger-docs
(need to be separately imported from compojure.api.swagger
).(defapi app
(swagger-routes)
(GET "/ping" []
(ok {:message "pong"})))
(defapi app
{:swagger {:ui "/", :spec "/swagger.json"}}
(GET "/ping" []
(ok {:message "pong"})))
request => type => matcher
as it is documented.
Previously required a type => matcher
map. Options are checked against type => matcher
coercion input, and a
descriptive error is thrown when api is created with the old options format.middlewares
to middleware
and :middlewares
key (restructuring) to :middleware
[function args]
[[wrap-foo {:opts :bar}]]
[#(wrap-foo % {:opts :bar})]
[(fn [handler] (wrap-foo handler {:opts :bar}))]
:parameters
key used by restructure-param
has been renamed to :swagger
.
public-resource-routes
& public-resources
are removed from compojure.api.middleware
.compojure.api.legacy
namespace has been removed.https://github.com/metosin/compojure-api/wiki/Migration-Guide-to-1.0.0
compojure.api.core
:
routes
& letroutes
, just like in the Compojure, but supporting Routing
undocumented
- works just like routes
but without any route definitions. Can be used to wrap legacy routes which setting the api option to fail on missing docs.api
is now just function, not a macro. It takes an optional options maps and a top-level route function.(fact "coercion is on for apiless routes"
(let [route (GET "/x" []
:query-params [x :- Long]
(ok))]
(route {:request-method :get :uri "/x" :query-params {}}) => throws))
[backtick "0.3.3"]
compojure.api.exception/with-logging
helper to add logging to exception handlers.
[metosin/ring-swagger "0.22.3"] is available
[metosin/ring-swagger "0.22.2"] is available
[metosin/ring-swagger-ui "2.1.4-0"] is available
[potemkin "0.4.3"] is available
[prismatic/schema "1.0.4"] is available but we use "1.0.3"
schema
& matcher
-input) for better performance.
api
and reading json-string out.[potemkin "0.4.2"] is available but we use "0.4.1"
[Ring-Swagger "0.22.1"]
clojure.tools.logging
is used with default uncaugt exception handling if it's found
on the classpath. Fixes #172.api
and defapi
produce identical swagger-docs. Fixes #159
[metosin/ring-swagger "0.22.1"] is available but we use "0.22.0"
[metosin/ring-swagger-ui "2.1.3-4"] is available but we use "2.1.3-2"
[prismatic/plumbing "0.5.2] is available but we use "0.5.1"
swagger-ui
now supports passing arbitrary options to SwaggerUI
(metosin/ring-swagger#67).[prismatic/schema "1.0.3"] is available but we use "0.4.4"
[prismatic/plumbing "0.5.1] is available but we use "0.4.4"
[metosin/schema-tools "0.7.0"] is available but we use "0.5.2"
[metosin/ring-swagger "0.22.0"] is available but we use "0.21.0"
[metosin/ring-swagger-ui "2.1.3-2"] is available but we use "2.1.2"