diff --git a/examples/http-swagger/src/example/server.clj b/examples/http-swagger/src/example/server.clj index d7083a88..2de6d8fc 100644 --- a/examples/http-swagger/src/example/server.clj +++ b/examples/http-swagger/src/example/server.clj @@ -112,9 +112,9 @@ {:status 200 :body {:total (- x y)}})}}]]] - {;;:reitit.interceptor/transform dev/print-context-diffs - :wrap-spec spell/closed-keys - :validate spec/validate + {;:reitit.interceptor/transform dev/print-context-diffs ;; pretty context diffs + :validate spec/validate ;; enable spec validation for route data + :reitit.spec/wrap spell/closed ;; strict top-level validation (alpha) :exception pretty/exception :data {:coercion spec-coercion/coercion :muuntaja m/instance diff --git a/modules/reitit-core/src/reitit/spec.cljc b/modules/reitit-core/src/reitit/spec.cljc index 11081f87..18a26b72 100644 --- a/modules/reitit-core/src/reitit/spec.cljc +++ b/modules/reitit-core/src/reitit/spec.cljc @@ -116,14 +116,14 @@ (defrecord Problem [path scope data spec problems]) -(defn validate-route-data [routes wrap-spec spec] +(defn validate-route-data [routes wrap spec] (some->> (for [[p d _] routes] - (when-let [problems (and spec (s/explain-data (wrap-spec spec) d))] + (when-let [problems (and spec (s/explain-data (wrap spec) d))] (->Problem p nil d spec problems))) (keep identity) (seq) (vec))) -(defn validate [routes {:keys [spec wrap-spec] :or {spec ::default-data, wrap-spec identity}}] - (when-let [problems (validate-route-data routes wrap-spec spec)] +(defn validate [routes {:keys [spec ::wrap] :or {spec ::default-data, wrap identity}}] + (when-let [problems (validate-route-data routes wrap spec)] (exception/fail! ::invalid-route-data {:problems problems}))) diff --git a/modules/reitit-dev/src/reitit/dev/pretty.cljc b/modules/reitit-dev/src/reitit/dev/pretty.cljc index 5b7d7d15..fa631723 100644 --- a/modules/reitit-dev/src/reitit/dev/pretty.cljc +++ b/modules/reitit-dev/src/reitit/dev/pretty.cljc @@ -230,9 +230,6 @@ :cljs "unknown")] (ex-info (exception-str message source (printer)) (assoc (or data {}) ::exception/cause e)))) -;; FIXME -(def closed-keys spec-tools.spell/closed-keys) - (defn de-expound-colors [^String s mappings] (let [s' (reduce (fn [s [from to]] diff --git a/modules/reitit-http/src/reitit/http/spec.cljc b/modules/reitit-http/src/reitit/http/spec.cljc index 9c54685e..f665c250 100644 --- a/modules/reitit-http/src/reitit/http/spec.cljc +++ b/modules/reitit-http/src/reitit/http/spec.cljc @@ -19,8 +19,8 @@ ;; (defn validate - [routes {:keys [spec wrap-spec] :or {spec ::data, wrap-spec identity}}] - (when-let [problems (rrs/validate-route-data routes :interceptors wrap-spec spec)] + [routes {:keys [spec ::rs/wrap] :or {spec ::data, wrap identity}}] + (when-let [problems (rrs/validate-route-data routes :interceptors wrap spec)] (exception/fail! ::rs/invalid-route-data {:problems problems}))) diff --git a/modules/reitit-ring/src/reitit/ring/spec.cljc b/modules/reitit-ring/src/reitit/ring/spec.cljc index e1af34c3..6cfaa299 100644 --- a/modules/reitit-ring/src/reitit/ring/spec.cljc +++ b/modules/reitit-ring/src/reitit/ring/spec.cljc @@ -35,21 +35,21 @@ :invalid non-specs})) (s/merge-spec-impl (vec specs) (vec specs) nil)) -(defn validate-route-data [routes key wrap-spec spec] +(defn validate-route-data [routes key wrap spec] (->> (for [[p _ c] routes [method {:keys [data] :as endpoint}] c :when endpoint :let [target (key endpoint) component-specs (seq (keep :spec target)) specs (keep identity (into [spec] component-specs)) - spec (wrap-spec (merge-specs specs))]] + spec (wrap (merge-specs specs))]] (when-let [problems (and spec (s/explain-data spec data))] (rs/->Problem p method data spec problems))) (keep identity) (seq))) (defn validate - [routes {:keys [spec wrap-spec] :or {spec ::data, wrap-spec identity}}] - (when-let [problems (validate-route-data routes :middleware wrap-spec spec)] + [routes {:keys [spec ::rs/wrap] :or {spec ::data, wrap identity}}] + (when-let [problems (validate-route-data routes :middleware wrap spec)] (exception/fail! ::rs/invalid-route-data {:problems problems}))) diff --git a/project.clj b/project.clj index 8b76504a..e2e5bd3b 100644 --- a/project.clj +++ b/project.clj @@ -27,7 +27,7 @@ [metosin/reitit-sieppari "0.3.1"] [metosin/reitit-pedestal "0.3.1"] [metosin/ring-swagger-ui "2.2.10"] - [metosin/spec-tools "0.9.1"] + [metosin/spec-tools "0.9.2-SNAPSHOT"] [metosin/schema-tools "0.11.0"] [metosin/muuntaja "0.6.4"] [metosin/jsonista "0.2.2"]