Skip to content

Undocumented routes when importing from different source file. #182

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
rcanepa opened this issue Dec 9, 2015 · 6 comments
Closed

Undocumented routes when importing from different source file. #182

rcanepa opened this issue Dec 9, 2015 · 6 comments
Milestone

Comments

@rcanepa
Copy link

rcanepa commented Dec 9, 2015

I am trying to organice my routes in separated files by their type/task (contacts, users, items, etc.) and then importing all of them in one main file in which I have configured the swagger documentation. However, all routes that have been imported from other files aren't being considered by swagger.

This is a extract of my main route table (swagger configuration belongs here):

(defn api-endpoint [{users-db :users-db contacts-db :contacts-db :as config}]
  (api
   (ring.swagger.ui/swagger-ui
    "/swagger-ui")
   (swagger-docs
    {:info {:title "SimpleClerk API"
            :description "SimpleClerk's CRM API"
            :tags [{:name "users" :description "Application's users."}
                   {:name "contacts"}
                   {:name "contacts_v2"}]}})

   (context* "/api/v1" []
             :tags ["api"]

             (context* "/users" []
                       :tags ["users"]

                       (GET* "/" []
                             :return [UserSchema]
                             :summary "Return the list of users."
                             (ok (fetch-users users-db)))

                       ;; ...
                       (DELETE* "/:id" []
                                :return s/Int
                                :path-params [id :- s/Uuid]
                                :summary "Delete the user with a given id."
                                (ok (delete-user! users-db id))))

             (context* "/contacts" []
                       :tags ["contacts"]
                       ;; importing contacts routes
                       (contacts-endpoint contacts-db)
                       ;; adding a dummy route for testing purposes
                       (GET* "/foo" []
                             :return s/Int
                             :summary "Dummy route"
                             (ok 1))

                       )

             )))

And my contacts routes files looks like this:

(defn contacts-endpoint [db]
  (defroutes* contacts-route []
    (GET* "/" []
          :return [Contact]
          :summary "Return the list of contacts."
          (ok (fetch-contacts db)))

    (POST* "/" []
           :return s/Uuid
           :body [contact Contact]
           :summary "Create a contact record."
           (ok (create-contact! db contact)))

    ))

You can see here that my configuration only shows me the dummy route and not the ones that I imported from the other file.
swaggerss

I am sure that those external routes are working because I can request them without problems. Any idea of what could be wrong in my configuration?

@ikitommi
Copy link
Member

ikitommi commented Dec 9, 2015

hi.

currently you can't do that. The swagger-docs (and reverse-route lookup-table) are generated at compile-time, not at runtime. So, currently, to get the swagger-docs out from extra routes, you need to define the extra routes as a Var, defined by defroutes*. See examples.

This is not good and a source of confusion, so the plan is to move all swagger-resolution from compile-time to run-time. Also gives other benefits like better support for Liberator & snappier dev-flow. Plan is to get this out before the end of the year. Before that, you should use defroutes* and pass the Dependencies to routes at runtime.

hope this helps.

@ikitommi
Copy link
Member

ikitommi commented Dec 9, 2015

see #178

@rcanepa
Copy link
Author

rcanepa commented Dec 9, 2015

Hi!

Good to know that this feature is in compojure-api's roadmap! Meanwhile, I will group my routes in one file because I want to keep my endpoint as system components. The defroutes* macro without a function enclosing it to inject dependencies is not compatible with what I want.

Thanks for your quick answer!

@ikitommi
Copy link
Member

ikitommi commented Jan 5, 2016

Working on this via #178 (comment).

@Deraen Deraen added this to the 1.0.0 milestone Jan 10, 2016
@ikitommi
Copy link
Member

this works on internal 1.0.0-SNAPSHOT.

@ikitommi
Copy link
Member

Merged in master. We will try to finalize 1.0.0 this/next week. See Changelog for details.

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

3 participants