From e0669ebbf80ccba81218b6a35cdcbb75cad94208 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 15 Oct 2024 17:53:28 +0200 Subject: [PATCH] :sparkles: Add minor improvements to schema and spec namespaces --- common/src/app/common/schema.cljc | 17 +++++++++++++++-- common/src/app/common/spec.cljc | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/common/src/app/common/schema.cljc b/common/src/app/common/schema.cljc index e7d716b3e..68089e2ea 100644 --- a/common/src/app/common/schema.cljc +++ b/common/src/app/common/schema.cljc @@ -271,7 +271,18 @@ (fast-check! s type code hint value))) (defn register! [type s] - (let [s (if (map? s) (m/-simple-schema s) s)] + (let [s (if (map? s) + (cond + (= :set (:type s)) + (m/-collection-schema s) + + (= :vec (:type s)) + (m/-collection-schema s) + + :else + (m/-simple-schema s)) + s)] + (swap! sr/registry assoc type s) nil)) @@ -400,7 +411,7 @@ ;; NOTE: this is general purpose set spec and should be used over the other -(register! ::set +(def type:set {:type :set :min 0 :max 1 @@ -477,6 +488,7 @@ {:pred pred + :empty #{} :type-properties {:title "set" :description "Set of Strings" @@ -491,6 +503,7 @@ ::oapi/items {:type "string"} ::oapi/unique-items true}}))}) +(register! ::set type:set) (register! ::vec {:type :vector diff --git a/common/src/app/common/spec.cljc b/common/src/app/common/spec.cljc index 5a8c23a38..38af56349 100644 --- a/common/src/app/common/spec.cljc +++ b/common/src/app/common/spec.cljc @@ -442,4 +442,3 @@ cause (when (ex/error? cause) (validation-error? (ex-data cause))))) -