-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically push context
parameters into endpoints when safe
#463
Comments
Great idea! |
If a context would be inferred as dynamic, we can push the context into each body form. Then we can proceed to handle individual cases, but the advantage is it automatically handles hybrid static/dynamic contexts. The inner contexts that are static will be inferred as static, ditto dynamic. (let [f (fn [] (GET "/bar" [] "body just for doc and coercion"))]
(context "/foo" []
:body [body s/Str]
(GET "/bar" [] body)
(f)))
=>
(let [f (fn [] (GET "/bar" [] "body just for doc and coercion"))]
(vector
(context "/foo" []
:body [body s/Str]
(GET "/bar" [] body))
(context "/foo" []
:body [body s/Str]
(f))))
=>
(let [f (fn [] (GET "/bar" [] "body just for doc and coercion"))]
(vector
(context "/foo" []
(GET "/bar" []
:body [body s/Str]
body))
(context "/foo" []
(-> (f)
(update :handler (let [g (partial coercion/coerce-request! s/Str :body-params :body true false)]
#(comp % g)))
(update-in [:info :public :parameters :body] #(or % s/Str)))))) |
Another insight is that if all This is a useful observation if the context body calls a function. If the function doesn't get passed the body, then we can just update the route after it's been evaluated. (let [f (fn [] (GET "/bar" [] "body just for doc and coercion"))]
(context "/foo" []
:body [body s/Str]
(f)))
=>
(let [f (fn [] (GET "/bar" [] "body just for doc and coercion"))]
(context "/foo" []
(-> (f)
...for each route...
(update :handler (let [g (partial coercion/coerce-request! s/Str :body-params :body true false)]
#(comp % g)))
(update-in [:info :public :parameters :body] #(or % s/Str))))) |
Presents more opportunities to infer static contexts.
=>
typed.clj.analyzer would be useful here as we both need to infer where locals occur and also do partial macroexpansion.
The text was updated successfully, but these errors were encountered: