Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Apr 24, 2024
1 parent 0564d39 commit 4f52bbe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
21 changes: 7 additions & 14 deletions src/compojure/api/meta.clj
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,12 @@
m))

(defn stage-letk-binder [binder]
(fnk-schema binder)
(fnk-schema binder) ;; syntax check
(assert (vector? binder))
(loop [outer-lets []
[fst snd thrd :as binder] binder
out []]
(let [g (gensym)]
(prn "binder" binder)
(prn "outer-lets" outer-lets)
(prn "out" out)
(if (empty? binder)
{:g g
:outer-lets (conj outer-lets g (strict (fnk-schema out)))
Expand All @@ -455,23 +452,18 @@
(recur (conj outer-lets g schema)
(subvec binder 3)
(conj out fst :- (if more-sym schema g))))
(let [_ (assert (>= (count binder) 2))
{:keys [outer-lets schema]} (if more-sym
(stage-map-schema `{s/Keyword s/Any} outer-lets)
{:outer-lets outer-lets
:schema thrd})]
(recur (conj outer-lets g schema)
(subvec binder 1)
(conj out fst :- (if more-sym schema g))))))
(recur (conj outer-lets g `s/Any)
(subvec binder 1)
(conj out fst :- g))))
(map? fst) (let [has-default (= 2 (count fst))
_ (assert (<= 1 (count fst) 2))
[k1 k2] (keys fst)
[schema-k default-k] (if has-default
[sym-k default-k] (if has-default
(if (= :- (get fst k1))
[k1 k2]
[k2 k1])
[k1])]
(assert (symbol? schema-k))
(assert (symbol? sym-k))
(recur (conj outer-lets g (if has-default default-k `s/Any))
(subvec binder 1)
(conj out (cond-> fst
Expand All @@ -480,6 +472,7 @@

(defmethod restructure-param :body-params [_ body-params acc]
(let [{:keys [g outer-lets binder]} (stage-letk-binder body-params)]
(prn {:g g :outer-lets outer-lets :binder binder})
(-> acc
(update :outer-lets into outer-lets)
(update-in [:letks] into [binder (src-coerce! g :body-params :body)])
Expand Down
6 changes: 2 additions & 4 deletions test/compojure/api/meta_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1020,15 +1020,13 @@
(ok "kikka"))
`(let [?expensive ~'EXPENSIVE
?field2-schema s/Any
?default-key (with-meta
(s/optional-key :default)
{:default '42})
?default-schema ~'s/Int
?more-keys ~'s/Keyword
?more-vals ~'s/Keyword
;;FIXME there's an extra schema here we should delete
?body-schema {:field ?expensive
:field2 ?field2-schema
?default-key ?default-schema
(with-meta (s/optional-key :default) {:default '42}) ?default-schema
?more-keys ?more-vals}]
(map->Route
{:path "/ping",
Expand Down

0 comments on commit 4f52bbe

Please sign in to comment.