From 1b1bdfbd047ed5fac53b33b53d998627a767d897 Mon Sep 17 00:00:00 2001 From: Benjamin Sigonneau Date: Sun, 1 Feb 2026 15:27:26 +0100 Subject: [PATCH] Move hardcoded values for OpenAPI to config --- src/yohoho/app.clj | 18 ++++++++++-------- src/yohoho/config.clj | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/yohoho/app.clj b/src/yohoho/app.clj index ec3a5a1..f524cb9 100644 --- a/src/yohoho/app.clj +++ b/src/yohoho/app.clj @@ -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}))) diff --git a/src/yohoho/config.clj b/src/yohoho/config.clj index b32c179..5066436 100644 --- a/src/yohoho/config.clj +++ b/src/yohoho/config.clj @@ -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"}})