Frontier vendoring #116

Merged
merged 2 commits into from Jan 5, 2012

Projects

None yet

3 participants

@jwkoelewijn
Contributor

class MyAPI < Grape::API
vendor 'v1', :using => :header, :vendor => 'twitter', :format => :json

get '/' do
'hello world'
end
end

and let it still return the '/' even when the accept-header
"application/vnd.some_other_vendor-v1+json" was given. This commit will
let it return a 404, and sets the X-Cascade pass as well.

I've added this because although the version is right, part of the
Accept header (the vendor part) is not correct.

@jwkoelewijn jwkoelewijn Added consideration of vendors when using header based version selection
class MyAPI < Grape::API
vendor 'v1', :using => :header, :vendor => 'twitter', :format => :json

get '/' do
'hello world'
end
end

and let it still return the '/' even when the accept-header
"application/vnd.some_other_vendor-v1+json" was given. This commit will
let it return a 404, and sets the X-Cascade pass as well.

I've added this because although the version is right, part of the
Accept header (the vendor part) is not correct.
cba257e
@dblock dblock commented on an outdated diff Jan 5, 2012
lib/grape/middleware/versioner/header.rb
@@ -35,7 +35,10 @@ def before
env['api.subtype'] = subtype
subtype.scan(/vnd\.(.+)?-(.+)?\+(.*)?/) do |vendor, version, format|
- if options[:versions] && !options[:versions].include?(version)
+ is_vendored = options[:version_options] && options[:version_options][:vendor]
+ correctly_vendored = is_vendored ? options[:version_options][:vendor] == vendor : true
dblock
dblock Jan 5, 2012 Owner

This may be a pedantic/style comment or maybe I don't understand what this is doing :)

"Correctly" jumped as a validation thing, which is not what we'redoing here. So the header is vendored, but then the header vendor matches (rather than correct), right? I would rename correctly_vendored to something like is_vendored_match to make the intent more specific.

Contributor

@dblock You were right, is_vendored_match is a semantically more correct name :)

@jch jch merged commit 5a3bc1e into ruby-grape:frontier Jan 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment