bploetz / versionist

A plugin for versioning Rails based RESTful APIs.
MIT License
972 stars 51 forks source link

Support subdirectory (e.g. 'api') for generators. #62

Closed joshuapinter closed 10 years ago

joshuapinter commented 10 years ago

I have all of my API stuff in an api directory, for example:

app/
  -controllers/
    --api/
      ---v2
        ----base_controller.rb
        ----check_controller.rb
        # etc

Because of this, a generator command, like:

rails generate versionist:copy_api_version v2 V2 v3 V3

Does not work because it cannot find anything in app/controllers/v2/, etc.:

No routes found in config/routes.rb for v2
No controllers found in app/controllers for v2
No controller specs found in spec/controllers for v2
# etc.

Here is my routes namespace for V2:

namespace :api do
  api_version module: 'V2', header: { name: "Accept", value: "application/vnd.emission-central.com; version=2" } do
    # etc.
  end
end

Thanks!

prasofty commented 10 years ago

Try this

  rails generate versionist:new_api_version v1 Api::V1 --path=value:v1 --default

  rails generate versionist:new_controller products Api::V1

  rails generate versionist:copy_api_version v1 Api::V1 v2 Api::V2

  api_version(:module => "Api::V2", :path => {:value => "api/v2"}) do
    ...
  end
joshuapinter commented 10 years ago

Thanks @prasofty. I ran the following command:

rails generate versionist:copy_api_version v3 Api::V3 v4 Api::V4

This seemed to find the controllers just fine but did not find the routes okay, as per the following output:

No routes found in config/routes.rb for v3
Copying all files from app/controllers/api/v3 to app/controllers/api/v4

Also, the views were not copied.

bploetz commented 10 years ago

Hey @joshuapinter I'm really sorry for the radio silence on this. I recently started working at a company that uses GitHub for its SCM, and for some reason that seems to have broken notifications to me about my personal repos. So I didn't see this until just now.

As for your issue, the following works for me:

rails generate versionist:copy_api_version api/v1 Api::V1 api/v2 Api::V2
       route  api_version(:module => "Api::V2", :header => {:name => "Accept", :value => "application/vnd.mycompany.com; version=1"}) do
  end
Copying all files from app/controllers/api/v1 to app/controllers/api/v2
Copying all files from test/functional/api/v1 to test/functional/api/v2
Copying all files from test/integration/api/v1 to test/integration/api/v2
Copying all files from app/presenters/api/v1 to app/presenters/api/v2
Copying all files from test/presenters/api/v1 to test/presenters/api/v2
Copying all files from app/helpers/api/v1 to app/helpers/api/v2
Copying all files from test/helpers/api/v1 to test/helpers/api/v2
Copying all files from public/docs/api/v1 to public/docs/api/v2
joshuapinter commented 10 years ago

Oh perfect, thanks @bploetz. I appreciate you closing the loop on this.

Cheers!