Move hardcoded values for OpenAPI to config
This commit is contained in:
@@ -19,11 +19,11 @@
|
||||
(ring/router
|
||||
(conj api-routes
|
||||
;; Add OpenAPI description to the default API routes
|
||||
["/openapi.json" {:get (openapi/create-openapi-handler)
|
||||
:no-doc true
|
||||
:openapi {:info {:title "Yo-ho-ho API"
|
||||
:description "A take-home assignment for HolidayPirates"
|
||||
:version "0.42.0"}}}])
|
||||
[(:json-url (:apidoc config)) {:get (openapi/create-openapi-handler)
|
||||
:no-doc true
|
||||
:openapi {:info {:title "Yo-ho-ho API"
|
||||
:description "A take-home assignment for HolidayPirates"
|
||||
:version "0.42.0"}}}])
|
||||
|
||||
;; Middlewares:
|
||||
;; - wrap-content-type-json: ensure POST routes are sent JSON payload
|
||||
@@ -39,7 +39,8 @@
|
||||
|
||||
(ring/routes
|
||||
;; 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
|
||||
(ring/create-default-handler
|
||||
{:not-found (constantly {:status 404
|
||||
@@ -50,9 +51,10 @@
|
||||
"HolidayPirates take-home assignement.
|
||||
Goal: build a (very) small REST API that exposes to endpoints."
|
||||
[& 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...")
|
||||
(db/init!)
|
||||
(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})))
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
|
||||
(def config
|
||||
{: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