Skip to content

Remove macro-peeling to get the swagger-docs out #178

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

Closed
ikitommi opened this issue Nov 25, 2015 · 3 comments
Closed

Remove macro-peeling to get the swagger-docs out #178

ikitommi opened this issue Nov 25, 2015 · 3 comments
Milestone

Comments

@ikitommi
Copy link
Member

Biggest source of Evil in Compojure-api is the custom macro-peeler, to resolve the swagger-docs.

Why it's bad:

  • swagger-docs are resolved at (Clojure) compile-time => extra latency in development as the whole handler sub-tree gets re-compiled.
  • need to use defroutes* => can't create subroutes via functions (passing system via closure)
  • but-ugly code to handle this

A better option:

  • Compojure-api wrapped routes (GET* etc) return Records/Types, from where we extract the swagger-docs at runtime via a Ring-swagger protocol.
  • We can still use compojure routing beneath, by making the Records invokable - or we could swicth the routing to totally something else, like bidi.

did a simple spike, looks promising.

@ikitommi ikitommi changed the title Remove macro-magic Remove macro-peeling to get the swagger-docs out Nov 25, 2015
@ikitommi ikitommi added this to the 0.25.0 milestone Nov 26, 2015
@ikitommi
Copy link
Member Author

ikitommi commented Jan 5, 2016

WIP in https://github.com/metosin/compojure-api/tree/runtime-route-resolution

Bye-bye defroutes*:

(facts "nested routes"
  (let [middleware (fn [handler] (fn [request] (handler request)))
        more-routes (fn [version]
                      (routes*
                        (GET* "/more" []
                          (ok {:message version}))))
        routes (context* "/api/:version" []
                 :path-params [version :- String]
                 (GET* "/ping" []
                   (ok {:message (str "pong - " version)}))
                 (middlewares* [middleware]
                   (GET* "/hello" []
                     :return {:message String}
                     :summary "cool ping"
                     :query-params [name :- String]
                     (ok {:message (str "Hello, " name)}))
                   (more-routes version)))]

    (fact "routes can be extracted at runtime"
      (let [routes (r/get-routes routes)]
        routes => [["/api/:version/ping" :get {:parameters {:path {:version String, s/Keyword s/Any}}}]
                   ["/api/:version/hello" :get {:parameters {:query {:name String, s/Keyword s/Any}
                                                             :path {:version String, s/Keyword s/Any}}
                                                :responses {200 {:description "", :schema {:message String}}}
                                                :summary "cool ping"}]
                   ["/api/:version/more" :get {:parameters {:path {:version String, s/Keyword s/Any}}}]]))))

@Deraen Deraen modified the milestones: 1.0.0, 0.25.0 Jan 10, 2016
@ikitommi
Copy link
Member Author

In one of the big c-api projects (with 100+ routes), the compile-time is no 750x faster with the new route collector.

@ikitommi
Copy link
Member Author

merged to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants