From 3cb387747b499c1a62f1b3729c17be8a93854ce4 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Fri, 19 Apr 2024 11:58:13 +0300 Subject: [PATCH] doc: use malli vars in examples/openapi --- examples/openapi/src/example/server.clj | 39 +++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/examples/openapi/src/example/server.clj b/examples/openapi/src/example/server.clj index 9070a529..77639e41 100644 --- a/examples/openapi/src/example/server.clj +++ b/examples/openapi/src/example/server.clj @@ -12,8 +12,28 @@ [reitit.ring.middleware.multipart :as multipart] [reitit.ring.middleware.parameters :as parameters] [ring.adapter.jetty :as jetty] + [malli.core :as malli] [muuntaja.core :as m])) +(def Transaction + [:map + [:amount :double] + [:from :string]]) + +(def AccountId + [:map + [:bank :string] + [:id :string]]) + +(def Account + [:map + [:bank :string] + [:id :string] + [:balance :double] + [:transactions [:vector #'Transaction]]]) + + + (def app (ring/ring-handler (ring/router @@ -89,8 +109,23 @@ [:email {:json-schema/example "heidi@alps.ch"} string?]]]}}}} :handler (fn [_request] - [{:name "Heidi" - :email "heidi@alps.ch"}])}}] + {:status 200 + :body [{:name "Heidi" + :email "heidi@alps.ch"}]})}}] + + ["/account" + {:get {:summary "Fetch an account | Recursive schemas using malli registry" + :parameters {:query #'AccountId} + :responses {200 {:content {:default {:schema #'Account}}}} + :handler (fn [_request] + {:status 200 + :body {:bank "MiniBank" + :id "0001" + :balance 13.5 + :transactions [{:from "0002" + :amount 20.0} + {:from "0003" + :amount -6.5}]}})}}] ["/secure" {:tags #{"secure"}