Git Product home page Git Product logo

api-versions's People

Contributors

coryfoy avatar davidcelis avatar nashby avatar rposborne avatar zorbash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

api-versions's Issues

url_for not working

Forgive me if I'm doing something wrong, but after setting up api-versions, if I use respond_with @foo inside API::V1::FooController, it squawks at me that "api_v1_foos_url" doesn't exist. Did I miss something?

Thanks,
Chad

RSpec routing specs and matches? method

Hello,

I am trying api-versions on a small project and encountered an issue with some of my already existing routing specs :

# encoding: UTF-8
require 'spec_helper'

describe 'Registrations' do

  it 'routes to #create' do
    expect(post('/users')).to route_to("api/v1/registrations#create")
  end

end

RSpec returns :

  1) Registrations routes to #create
     Failure/Error: expect(post('/users')).to route_to("api/v1/registrations#create")
     NoMethodError:
       undefined method `split' for nil:NilClass
     # ./spec/routing/registrations_routing_spec.rb:7:in `block (2 levels) in <top (required)>'

Indeed, actually the gem tried to do a split on a non existing header :

    def matches?(request)
      accepts = request.headers['Accept'].split(',')
      accepts.any? do |accept|
        accept.strip!
        accepts_proper_format?(accept) && (matches_version?(accept) || unversioned?(accept))
      end

Cf. that file.

On routing specs it seems that there is no way to specify an Accept header. More, since the last changes on default version, I guess that at that point of the code we should already have a default version in Accept header so that the split doesn't fail.

PS : yes I'm on the current master branch.

Fixing the default headers has broken non JSON tests

I'm using Rails 4 and Ruby 2.0. The change to setting default headers breaks all my none JSON tests. My Rails app has some HTML pages as well. The error I get is:

ActionController::UnknownFormat (ActionController::UnknownFormat)
./features/step_definitions/user_steps.rb:42:in `sign_in'
./features/step_definitions/user_steps.rb:74:in `/^I sign in with valid credentials$/'
features/users/sign_in.feature:22:in `When I sign in with valid credentials'

I used Rails composer to create the basic framework so the tests are their defaults.

If I revert to the latest published gem (1.2.0) everything is ok again.

Supporting controller specs

Hey,

First of all, love the work you've done with this! :)

It has been documented, and verified, that controller specs no longer work when you use this library and request specs work fine.

That said, I would love to still be able to use controller specs, simply because they don't touch routing and are faster to execute. Is there a way in which I can still use controller specs for some of my controllers?

How to specify the default format

I would like to specify the format.
Could you let me know if you have any better ideas than using the defaults block?

  api vendor_string: 'foo', default_version: 1 do
    defaults format: :json do
      version 1 do
        cache as: 'v1' do
        :
        end
      end
    end
  end

[question] API namespace

Hello,

Quick question, actually not an issue here. :)

I would like to know if there's a 'clean' way of removing default api namespace which is added by the gem.

Actually, I would like to directly have something like that : app/controllers/v1 and not app/controllers/api/v1.

Accept Header format

currently you are only supporting the following format application/vnd.myvendor+json;version=1 for the Accept header...

Is it possible to also support the following format application/vnd.myvendor.v1+json ? similar to github accept header which IMHO think cleaner format

I can't get tests working following the example

My routes.rb is as follows:

api vendor_string: "test", default_version: 1, defaults: { format: 'json' } do
  version 1 do
    cache as: 'v1' do
      resources :jobs
    end
  end
end

And my rspec test follows the example test:

require 'spec_helper'

describe Api::V1::JobsController do
  describe "GET 'index'" do
    it "should be successful" do
      get '/api/jobs', {}, 'HTTP_ACCEPT' => 'application/vnd.test+json; version=1'
      response.should be_success
    end
  end
end

But I get the following my tests:

1) Api::V1::JobsController GET 'index' should be successful
   Failure/Error: get '/api/jobs', {}, 'HTTP_ACCEPT' => 'application/vnd.test+json; version=1'
   ActionController::UrlGenerationError:
   No route matches {:controller=>"api/v1/jobs", :action=>"/api/jobs"}
 # ./spec/controllers/api/v1/jobs_controller_spec.rb:6:in `block (3 levels) in <top (required)>'

I've tried the most recent published gem and also the latest version direct from GitHub and the result is the same. If I view from the browser or curl at the command line, it's successful:

[{"job":{}}]

Cut a new gem version to contain #6

54eaadb fixes a common bug where:

curl -i -XGET http://localhost:3000/api/bar/new \
     -H 'Accept: '

Would respond with a 500 due to:

ERROR NoMethodError: undefined method `split' for nil:NilClass
    /home/zorbash/dev/gems/api-versions/lib/api-versions/version_check.rb:12:in `matches?'

A new gem version has to be released to contain the fix.

Unexpected default vendor accept header.

According to a middleware spec, ApiVersions::Middleware should add a default vendor accept to a nil Accept header.

But, in my opinion, it adds default vendor only if request path contains prefix path like /api. Otherwise, It adds default vendor when request path is / and Accept header is */*.

What do you think of this?

Thank you for sharing this project. ๐Ÿ‘

Middleware intercept crashes if no ACCEPT passed.

Monitoring services such as pingdom do not set accept headers.

api-versions-1.1.0/lib/api-versions/middleware.rb:8โ†’ call
warden-1.2.1/lib/warden/manager.rb:35โ†’ block in call

Will do a pull request shortly.

How to inherit only few methods from v1 version

I don't know whether it is handled or not but I didn't find any documentation regarding inheriting only few methods from previous version.

eg.

api vendor_string: "myvendor", default_version: 1 do
   version 1 do
     cache as: 'v1' do
        resources :authorizations
     end
   end
   version 2 do
     inherit from: 'v1'
     # Now I want only `index` action to inherit from authorizations and want to modify other actions of authorization controller. How to do this?
   end
end

Thanks.

Namespaced controllers no longer detected

I have an application with a controller at app/controllers/api/v1/brewery_db/webhooks_controller.rb and the following routes:

Goodbrews::Application.routes.draw do
  api vendor_string: 'goodbrews', default_version: 1, path: '' do
    version 1 do
      cache as: 'v1' do
        namespace :brewery_db do
          resources :webhooks, only: [] do
            collection do
              get 'beer'
              post 'brewery'
              post 'location'
              post 'guild'
              post 'event'
            end
          end
        end
      end
    end
  end
end

Running rake routes shows the expected:

                          Prefix Verb URI Pattern                             Controller#Action
    beer_api_brewery_db_webhooks GET  /brewery_db/webhooks/beer(.:format)     api/v1/brewery_db/webhooks#beer {:vendor_string=>"goodbrews", :default_version=>1}
 brewery_api_brewery_db_webhooks POST /brewery_db/webhooks/brewery(.:format)  api/v1/brewery_db/webhooks#brewery {:vendor_string=>"goodbrews", :default_version=>1}
location_api_brewery_db_webhooks POST /brewery_db/webhooks/location(.:format) api/v1/brewery_db/webhooks#location {:vendor_string=>"goodbrews", :default_version=>1}
   guild_api_brewery_db_webhooks POST /brewery_db/webhooks/guild(.:format)    api/v1/brewery_db/webhooks#guild {:vendor_string=>"goodbrews", :default_version=>1}
   event_api_brewery_db_webhooks POST /brewery_db/webhooks/event(.:format)    api/v1/brewery_db/webhooks#event {:vendor_string=>"goodbrews", :default_version=>1}

When I try to visit /brewery_db/webhooks/beer (which I changed to a GET for testing), I get No route matches [GET] "/brewery_db/webhooks/beer".

Changing my routes from

Goodbrews::Application.routes.draw do
  api vendor_string: 'goodbrews', default_version: 1, path: '' do
    version 1 do
      cache as: 'v1' do
        # ...

to

namespace :api, path: ''
  namespace :v1, path: ''
    # ...

Makes my routes work as expected. Something in api-versions seems to be messing with namespacing.

Correctly pass all Rails Routing DSL options through api-versions

There are some instances where certain Rails routing options don't work from within api_namespaces. For example, #11 mentions the :path option being ignored from within :shallow routes and #12 brings up the point that we always set :namespace to 'api'. We should handle these options better.

default_version does nothing?

If I'm reading the source code right, then the file that sets the default header doesn't actually use the default_version config option.

https://github.com/erichmenge/api-versions/blob/master/lib/api-versions/middleware.rb

So, I think currently if you don't manually set the header then the middleware sets the version to 1, regardless of the value of default_version.

I would expect it to set the header to default_version and if that's not set then 1.

In fact searching the repo it looks like default_version isn't really used at all (though search might be dodgy) https://github.com/erichmenge/api-versions/search?q=default_version&source=c

Otherwise great gem, love being able to read all the code in one sitting, thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.