Move hardcoded values for OpenAPI to config
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
(ring/router
|
(ring/router
|
||||||
(conj api-routes
|
(conj api-routes
|
||||||
;; Add OpenAPI description to the default API routes
|
;; Add OpenAPI description to the default API routes
|
||||||
["/openapi.json" {:get (openapi/create-openapi-handler)
|
[(:json-url (:apidoc config)) {:get (openapi/create-openapi-handler)
|
||||||
:no-doc true
|
:no-doc true
|
||||||
:openapi {:info {:title "Yo-ho-ho API"
|
:openapi {:info {:title "Yo-ho-ho API"
|
||||||
:description "A take-home assignment for HolidayPirates"
|
:description "A take-home assignment for HolidayPirates"
|
||||||
@@ -39,7 +39,8 @@
|
|||||||
|
|
||||||
(ring/routes
|
(ring/routes
|
||||||
;; Add Swagger UI
|
;; Add Swagger UI
|
||||||
(swagger-ui/create-swagger-ui-handler {:path "/doc" :url "/openapi.json"})
|
(swagger-ui/create-swagger-ui-handler {:path (:ui-url (:apidoc config))
|
||||||
|
:url (:json-url (:apidoc config))})
|
||||||
;; Default route: anything not explicitely handled should give a 404
|
;; Default route: anything not explicitely handled should give a 404
|
||||||
(ring/create-default-handler
|
(ring/create-default-handler
|
||||||
{:not-found (constantly {:status 404
|
{:not-found (constantly {:status 404
|
||||||
@@ -50,9 +51,10 @@
|
|||||||
"HolidayPirates take-home assignement.
|
"HolidayPirates take-home assignement.
|
||||||
Goal: build a (very) small REST API that exposes to endpoints."
|
Goal: build a (very) small REST API that exposes to endpoints."
|
||||||
[& args]
|
[& args]
|
||||||
(let [{{port :port} :server} config]
|
(let [{{port :port} :server} config
|
||||||
|
{{json-doc :json-url ui-doc :ui-url} :apidoc} config]
|
||||||
(println "Initializing SQLite database...")
|
(println "Initializing SQLite database...")
|
||||||
(db/init!)
|
(db/init!)
|
||||||
(println "Ahoy! Yo-ho-ho API starting on port" port)
|
(println "Ahoy! Yo-ho-ho API starting on port" port)
|
||||||
(println "API documentation on /openapi.json and on /doc (interactive UI)")
|
(println "API documentation on" json-doc "and on" ui-doc "(interactive UI)")
|
||||||
(http-server/run-jetty app {:port port})))
|
(http-server/run-jetty app {:port port})))
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
|
|
||||||
(def config
|
(def config
|
||||||
{:db {:dbtype "sqlite" :dbname "yohoho.db"}
|
{:db {:dbtype "sqlite" :dbname "yohoho.db"}
|
||||||
:server {:port 3000}})
|
:server {:port 3000}
|
||||||
|
:apidoc {:json-url "/openapi.json" :ui-url "/doc"}})
|
||||||
|
|||||||
Reference in New Issue
Block a user