From 47906df7b9c9f140380588e457a8b937e9fb5f02 Mon Sep 17 00:00:00 2001 From: Tommi Reiman Date: Sat, 15 Jun 2019 11:49:11 +0300 Subject: [PATCH] Update deps & docs --- CHANGELOG.md | 17 ++++++++++++++++- doc/basics/route_syntax.md | 13 +++++++++++++ project.clj | 12 ++++++------ test/cljc/reitit/coercion_test.cljc | 12 ++++++------ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f48d0ca0..988be566 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,22 +12,37 @@ We use [Break Versioning][breakver]. The version numbers follow a `.clojure, via [schema-tools](https://github.com/metosin/schema-tools). + * Add support for explixit selection of router path-parameter `:syntax`, fixes [#276](https://github.com/metosin/reitit/issues/276) ```clj (require '[reitit.core :as r]) +;; default +(-> (r/router + ["http://localhost:8080/api/user/{id}" ::user-by-id]) + (r/match-by-path "http://localhost:8080/api/user/123")) +;#Match{:template "http://localhost:8080/api/user/{id}", +; :data {:name :user/user-by-id}, +; :result nil, +; :path-params {:id "123", :8080 ":8080"}, +; :path "http://localhost:8080/api/user/123"} + + +;; just bracket-syntax (-> (r/router ["http://localhost:8080/api/user/{id}" ::user-by-id] {:syntax :bracket}) diff --git a/doc/basics/route_syntax.md b/doc/basics/route_syntax.md index 3794a2d7..6c1dbc03 100644 --- a/doc/basics/route_syntax.md +++ b/doc/basics/route_syntax.md @@ -134,6 +134,19 @@ Routes are just data, so it's easy to create them programmatically: Router options `:syntax` allows the path-parameter syntax to be explicitely defined. It takes a keyword or set of keywords as a value. Valid values are `:colon` and `:bracket`. Default value is `#{:colon :bracket}`. +With defaults: + +```clj +(-> (r/router + ["http://localhost:8080/api/user/{id}" ::user-by-id]) + (r/match-by-path "http://localhost:8080/api/user/123")) +;#Match{:template "http://localhost:8080/api/user/{id}", +; :data {:name :user/user-by-id}, +; :result nil, +; :path-params {:id "123", :8080 ":8080"}, +; :path "http://localhost:8080/api/user/123"} +``` + Supporting only `:bracket` syntax: ```clj diff --git a/project.clj b/project.clj index 0d6e6cc4..78c96168 100644 --- a/project.clj +++ b/project.clj @@ -28,7 +28,7 @@ [metosin/reitit-pedestal "0.3.7"] [metosin/ring-swagger-ui "2.2.10"] [metosin/spec-tools "0.9.3"] - [metosin/schema-tools "0.11.0"] + [metosin/schema-tools "0.12.0"] [metosin/muuntaja "0.6.4"] [metosin/jsonista "0.2.3"] [metosin/sieppari "0.0.0-alpha7"] @@ -48,7 +48,7 @@ [lein-cljsbuild "1.1.7"] [lein-cloverage "1.1.1"] [lein-codox "0.10.7"] - [metosin/bat-test "0.4.2"]] + [metosin/bat-test "0.4.3"]] :profiles {:dev {:jvm-opts ^:replace ["-server"] @@ -96,16 +96,16 @@ [criterium "0.4.5"] [org.clojure/test.check "0.9.0"] - [org.clojure/tools.namespace "0.2.11"] + [org.clojure/tools.namespace "0.3.0"] [com.gfredericks/test.chuck "0.2.9"] [io.pedestal/pedestal.service "0.5.5"] - [org.clojure/core.async "0.4.490"] + [org.clojure/core.async "0.4.500"] [manifold "0.1.8"] [funcool/promesa "2.0.1"] - [com.clojure-goes-fast/clj-async-profiler "0.3.1"] + [com.clojure-goes-fast/clj-async-profiler "0.4.0"] [ring-cors "0.1.13"] [com.bhauman/rebel-readline "0.1.4"]]} @@ -120,7 +120,7 @@ [io.pedestal/pedestal.service "0.5.5"] [io.pedestal/pedestal.jetty "0.5.5"] [calfpath "0.7.2"] - [org.clojure/core.async "0.4.490"] + [org.clojure/core.async "0.4.500"] [manifold "0.1.8"] [funcool/promesa "2.0.1"] [metosin/sieppari] diff --git a/test/cljc/reitit/coercion_test.cljc b/test/cljc/reitit/coercion_test.cljc index 202667fd..73c8c7a9 100644 --- a/test/cljc/reitit/coercion_test.cljc +++ b/test/cljc/reitit/coercion_test.cljc @@ -14,11 +14,11 @@ [["/schema" {:coercion reitit.coercion.schema/coercion} ["/:number/:keyword" {:parameters {:path {:number s/Int :keyword s/Keyword} - :query (s/maybe {:int s/Int, :ints [s/Int]})}}]] + :query (s/maybe {:int s/Int, :ints [s/Int], :map {s/Int s/Int}})}}]] ["/spec" {:coercion reitit.coercion.spec/coercion} ["/:number/:keyword" {:parameters {:path {:number int? :keyword keyword?} - :query (ds/maybe {:int int?, :ints [int?]})}}]] + :query (ds/maybe {:int int?, :ints [int?], :map {int? int?}})}}]] ["/none" ["/:number/:keyword" {:parameters {:path {:number int? :keyword keyword?}}}]]] @@ -30,8 +30,8 @@ (is (= {:path {:keyword :abba, :number 1}, :query nil} (coercion/coerce! m)))) (let [m (r/match-by-path r "/schema/1/abba")] - (is (= {:path {:keyword :abba, :number 1}, :query {:int 10, :ints [1,2,3]}} - (coercion/coerce! (assoc m :query-params {"int" "10", "ints" ["1" "2" "3"]})))))) + (is (= {:path {:keyword :abba, :number 1}, :query {:int 10, :ints [1,2,3], :map {1 1}}} + (coercion/coerce! (assoc m :query-params {"int" "10", "ints" ["1" "2" "3"], "map" {:1 :1}})))))) (testing "throws with invalid input" (let [m (r/match-by-path r "/schema/kikka/abba")] (is (thrown? ExceptionInfo (coercion/coerce! m)))))) @@ -42,8 +42,8 @@ (is (= {:path {:keyword :abba, :number 1}, :query nil} (coercion/coerce! m)))) (let [m (r/match-by-path r "/schema/1/abba")] - (is (= {:path {:keyword :abba, :number 1}, :query {:int 10, :ints [1,2,3]}} - (coercion/coerce! (assoc m :query-params {"int" "10", "ints" ["1" "2" "3"]})))))) + (is (= {:path {:keyword :abba, :number 1}, :query {:int 10, :ints [1,2,3], :map {1 1}}} + (coercion/coerce! (assoc m :query-params {"int" "10", "ints" ["1" "2" "3"], "map" {:1 :1}})))))) (testing "throws with invalid input" (let [m (r/match-by-path r "/spec/kikka/abba")] (is (thrown? ExceptionInfo (coercion/coerce! m))))))