bploetz / versionist

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

Error if multiple versioning strategies used in a request? #72

Closed johnrees closed 8 years ago

johnrees commented 8 years ago

I'll submit a failing spec for this if other people have experienced it?

If I have this in my routes -

api_version(module: "V01", path: {value: "v0.1"}, header: {name: "Accept", value: "application/vnd.url.com; version=0.1"}, default: true, defaults: { format: :json }) do
  resources :things
end

I can access these URLs

url.com/v0.1/things/1 url.com/things/1 { Accept: "application/vnd.url.com; version=0.1" }

but if I try to use both strategies and submit the header with the path

url.com/v0.1/things/1 { Accept: "application/vnd.url.com; version=0.1" }

I get a 404. Did I miss something?

bploetz commented 8 years ago

Huh, weird. I took a quick peek at the specs and I don't see a test for this case, so could very well be a bug.

bploetz commented 8 years ago

I can't reproduce this in a test Rails 4.1 app.

config/routes.rb:

    api_version(module: 'V01', path: {value: 'v0.1'}, header: {name: "Accept", value: "application/vnd.url.com; version=0.1"}, default: true, defaults: {format: :json}) do
      resources :foos
    end

app/controllers/v01/foos_controller.rb:

class V01::FoosController < V01::BaseController
  def index
    render :text => "hi"
  end
end

Requests:

> curl http://localhost:3000/foos
hi
> curl http://localhost:3000/v0.1/foos
hi
> curl -H "Accept: application/vnd.url.com; version=0.1" http://localhost:3000/v0.1/foos
hi

@johnrees what version of Rails are you using? Are you passing anything else in the Accept header besides the version string when you make the request that results in a 404?

bploetz commented 8 years ago

Closing due to radio silence. Re-open if @johnrees gets back to us on this one.