Review small fixes

This commit is contained in:
Tommi Reiman 2019-02-28 09:53:50 +02:00
parent 358f6d8932
commit 778a8b97b9
8 changed files with 19 additions and 47 deletions

View file

@ -147,7 +147,7 @@ Expanded routes:
```
## Expansion
## Customizing Expansion
By default, router `:expand` option has value `r/expand` function, backed by a `r/Expand` protocol. Expansion can be customized either by swapping the `:expand` implementation or by extending the Protocol. `r/Expand` implementations can be recursive.
@ -169,4 +169,4 @@ Page [shared routes](../advanced/shared_routes.md#using-custom-expander) has an
## Route data validation
See [Route data validation](route_data_validation.md), which enables an architecture of both [adaptive and principled](https://youtu.be/x9pxbnFC4aQ?t=1907) components.
See [Route data validation](route_data_validation.md).

View file

@ -261,7 +261,7 @@ public class Trie {
@Override
public int depth() {
return Arrays.stream(childs).mapToInt(Matcher::depth).max().orElseThrow(NoSuchElementException::new);
return Arrays.stream(childs).mapToInt(Matcher::depth).max().orElseThrow(NoSuchElementException::new) + 1;
}
@Override

View file

@ -12,7 +12,7 @@
"Pluggable coercion protocol"
(-get-name [this] "Keyword name for the coercion")
(-get-options [this] "Coercion options")
(-get-apidocs [this spesification data] "Returns api documentation")
(-get-apidocs [this specification data] "Returns api documentation")
(-compile-model [this model name] "Compiles a model")
(-open-model [this model] "Returns a new model which allows extra keys in maps")
(-encode-error [this error] "Converts error in to a serializable format")
@ -136,14 +136,14 @@
;; api-docs
;;
(defn get-apidocs [this spesification data]
(defn get-apidocs [this specification data]
(let [swagger-parameter {:query :query
:body :body
:form :formData
:header :header
:path :path
:multipart :formData}]
(case spesification
(case specification
:swagger (->> (update
data
:parameters
@ -152,7 +152,7 @@
(map (fn [[k v]] [(swagger-parameter k) v]))
(filter first)
(into {}))))
(-get-apidocs this spesification)))))
(-get-apidocs this specification)))))
;;
;; integration

View file

@ -44,7 +44,7 @@
"Available interceptors in registry:\n"
(with-out-str
(pprint/print-table [:id :description] (for [[k v] registry] {:id k :description v}))))
"see [reitit.interceptor/router] on how to add interceptor to the registry.\n") "\n")
"See [reitit.interceptor/router] on how to add interceptor to the registry.\n") "\n")
{:id this
:registry registry})))

View file

@ -28,7 +28,7 @@
"Available middleware in registry:\n"
(with-out-str
(pprint/print-table [:id :description] (for [[k v] registry] {:id k :description v}))))
"see [reitit.middleware/router] on how to add middleware to the registry.\n") "\n")
"See [reitit.middleware/router] on how to add middleware to the registry.\n") "\n")
{:id this
:registry registry})))

View file

@ -46,9 +46,9 @@
(reify coercion/Coercion
(-get-name [_] :schema)
(-get-options [_] opts)
(-get-apidocs [this spesification {:keys [parameters responses]}]
(-get-apidocs [this specification {:keys [parameters responses]}]
;; TODO: this looks identical to spec, refactor when schema is done.
(case spesification
(case specification
:swagger (swagger/swagger-spec
(merge
(if parameters
@ -69,8 +69,8 @@
$))]))})))
(throw
(ex-info
(str "Can't produce Schema apidocs for " spesification)
{:type spesification, :coercion :schema}))))
(str "Can't produce Schema apidocs for " specification)
{:type specification, :coercion :schema}))))
(-compile-model [_ model _] model)
(-open-model [_ schema] (st/open-schema schema))
(-encode-error [_ error]

View file

@ -91,8 +91,8 @@
(reify coercion/Coercion
(-get-name [_] :spec)
(-get-options [_] opts)
(-get-apidocs [this spesification {:keys [parameters responses]}]
(case spesification
(-get-apidocs [this specification {:keys [parameters responses]}]
(case specification
:swagger (swagger/swagger-spec
(merge
(if parameters
@ -113,8 +113,8 @@
$))]))})))
(throw
(ex-info
(str "Can't produce Spec apidocs for " spesification)
{:spesification spesification, :coercion :spec}))))
(str "Can't produce Spec apidocs for " specification)
{:specification specification, :coercion :spec}))))
(-compile-model [_ model name]
(into-spec model name))
(-open-model [_ spec] spec)

View file

@ -207,39 +207,11 @@
(routing-test2)
(reverse-routing-test))
(import '[reitit Trie])
(set! *warn-on-reflection* true)
(comment
(let [trie ]
(import '[reitit Trie])
(set! *warn-on-reflection* true)
(println
(Trie/lookup trie "/auth/login"))
;; 27ns
(cc/quick-bench
(dotimes [_ 1000]
(Trie/lookup trie "/auth/login")))
(println
(Trie/lookup trie "/auth/recovery/token/123"))
;; 82ns
(cc/quick-bench
(dotimes [_ 1000]
(Trie/lookup trie "/auth/recovery/token/123")))
(println
(Trie/lookup trie "/workspace/1/1"))
;; 96ns
(cc/quick-bench
(dotimes [_ 1000]
(Trie/lookup trie "/workspace/1/1")))))
(comment
(let [trie (Trie/linearMatcher
[(Trie/staticMatcher
"/auth/" (Trie/linearMatcher