Skip to content

Commit

Permalink
Merge pull request ruby-grape#181 from dblock/dont-cache-base-path
Browse files Browse the repository at this point in the history
Support multi-tenanted APIs, don't cache base_path.
  • Loading branch information
dblock committed Nov 28, 2014
2 parents 79cd89e + 4249c61 commit c4f49d1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 24 deletions.
12 changes: 6 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2014-11-28 11:04:19 -0500 using RuboCop version 0.27.0.
# on 2014-11-28 11:38:25 -0500 using RuboCop version 0.27.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 8
Metrics/AbcSize:
Max: 331
Max: 327

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 392
Max: 394

# Offense count: 4
Metrics/CyclomaticComplexity:
Max: 93

# Offense count: 204
# Offense count: 202
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 254

# Offense count: 13
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 357
Max: 359

# Offense count: 4
Metrics/PerceivedComplexity:
Max: 98
Max: 96

# Offense count: 7
Style/ClassVars:
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* [#176](https://github.com/tim-vandecasteele/grape-swagger/pull/176): Added ability to load nested models recursively - [@sergey-verevkin](https://github.com/sergey-verevkin).
* [#179](https://github.com/tim-vandecasteele/grape-swagger/pull/179): Document `Virtus::Attribute::Boolean` as boolean - [@eashman](https://github.com/eashman), [@dblock](https://github.com/dblock).
* [#178](https://github.com/tim-vandecasteele/grape-swagger/issues/178): Fixed `Hash` parameters, now exposed as Swagger `object` types - [@dblock](https://github.com/dblock).

* [#167](https://github.com/tim-vandecasteele/grape-swagger/pull/167): Support mutli-tenanted APIs, don't cache `base_path` - [@bradrobertson](https://github.com/bradrobertson), (https://github.com/dblock).
* Your contribution here.

### 0.8.0 (August 30, 2014)
Expand Down
3 changes: 1 addition & 2 deletions lib/grape-swagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def self.setup(options)
@@markdown = options[:markdown] ? GrapeSwagger::Markdown.new(options[:markdown]) : nil
@@hide_format = options[:hide_format]
api_version = options[:api_version]
base_path = options[:base_path]
authorizations = options[:authorizations]
root_base_path = options[:root_base_path]
extra_info = options[:info]
Expand Down Expand Up @@ -214,7 +213,7 @@ def self.setup(options)
apis: apis
}

base_path = parse_base_path(base_path, request)
base_path = parse_base_path(options[:base_path], request)
api_description[:basePath] = base_path if base_path && base_path.size > 0 && root_base_path != false
api_description[:models] = parse_entity_models(models) unless models.empty?
api_description[:authorizations] = authorizations if authorizations
Expand Down
33 changes: 18 additions & 15 deletions spec/non_default_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,34 @@ class ProcBasePathMountedApi < Grape::API

class SimpleApiWithProcBasePath < Grape::API
mount ProcBasePathMountedApi
add_swagger_documentation base_path: proc { |request| "#{request.base_url}/some_value" }
add_swagger_documentation base_path: proc { |request| [request.base_url, request.params[:base_path], 'some_value'].compact.join('/') }
end
end

def app
SimpleApiWithProcBasePath
end

subject do
get '/swagger_doc/something.json'
JSON.parse(last_response.body)
context 'default' do
subject do
get '/swagger_doc/something.json'
JSON.parse(last_response.body)
end

it 'retrieves the same given base-path for mounted-api' do
expect(subject['basePath']).to eq 'http://example.org/some_value'
end
end

# it "retrieves the given base-path on /swagger_doc" do
# get '/swagger_doc.json'
# JSON.parse(last_response.body)["basePath"].should == "http://example.org/some_value"
# end
context 'param' do
subject do
get '/swagger_doc/something.json?base_path=foobar'
JSON.parse(last_response.body)
end

it 'retrieves the same given base-path for mounted-api' do
expect(subject['basePath']).to eq 'http://example.org/some_value'
it 're-evaluates base-path' do
expect(subject['basePath']).to eq 'http://example.org/foobar/some_value'
end
end
end

Expand Down Expand Up @@ -97,11 +105,6 @@ def app
JSON.parse(last_response.body)
end

# it "retrieves the given base-path on /swagger_doc" do
# get '/swagger_doc.json'
# JSON.parse(last_response.body)["basePath"].should == "http://example.org/some_value"
# end

it 'retrieves the same given base-path for mounted-api' do
get '/swagger_doc/something.json'
expect(subject['basePath']).to eq 'http://example.org/some_value'
Expand Down

0 comments on commit c4f49d1

Please sign in to comment.