grape-swagger 0.20.1 → 0.20.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7b49d3317f5b9d9082b501e10b2a7fd14715cbc
4
- data.tar.gz: badfe74ba2b87d06cdfd44c98e9ce3e26a9bb30e
3
+ metadata.gz: 5e7244ce5e2e54fd314fdf08bb3a948aa85c1981
4
+ data.tar.gz: c2647e5425cfd200375341daf3ee1f691709863b
5
5
  SHA512:
6
- metadata.gz: bff5776130052d3c48d45a2a26bc59cef0ad264bfd5adaf197280019ba79476c5e8e6c9566a7c345b595664df5e27ccc259986c9d94d010873636a6d9e49eb6b
7
- data.tar.gz: 1685bef67cd8be2e477dab910d42e1236409b38040a34f08697ccc3fdd5ae8871d73b05b00e25f1c8b1ab96f3f158d8f9ee8c6817e83532bd9f5bb2044137ad1
6
+ metadata.gz: ebce21c42bb460babe20f85d0b4e020d111f5c992be70e4b58595cdd6e3efc9e0c7060eca217f32dba61d6e0c422ba9a3243f995cf41fae265076ab0e6298362
7
+ data.tar.gz: a6b0ac5ec95360f00a86eeff4107499caa33b2d55c70f243a5132e538945d68d46bae621dd58026a30254d8b005f4e291ca171b50a88bc28d7fe77661d406f59
@@ -4,6 +4,10 @@
4
4
 
5
5
  #### Fixes
6
6
 
7
+ * [#394](https://github.com/ruby-grape/grape-swagger/pull/394): removes overiding default trough example - [@LeFnord](https://github.com/LeFnord).
8
+ * [#393](https://github.com/ruby-grape/grape-swagger/pull/393): properly handle header parameters - [@wleeper](https://github.com/wleeper).
9
+ * [#389](https://github.com/ruby-grape/grape-swagger/pull/389): respect X-Forwarded-Host - [@edvakf](https://github.com/edvakf).
10
+
7
11
  ### 0.20.1 / 2016-04-17
8
12
 
9
13
  #### Features
data/README.md CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  * [What is grape-swagger?](#what)
9
9
  * [Related Projects](#related)
10
+ * [Compatibility](#version)
10
11
  * [Swagger-Spec](#swagger-spec)
11
12
  * [Installation](#install)
12
13
  * [Usage](#usage)
@@ -31,9 +32,22 @@ These screenshot is based on the [Hussars](https://github.com/LeFnord/hussars) s
31
32
  ## Related Projects
32
33
 
33
34
  * [Grape](https://github.com/ruby-grape/grape)
35
+ * [Grape Entity](https://github.com/ruby-grape/grape-entity)
34
36
  * [Swagger UI](https://github.com/wordnik/swagger-ui)
35
37
 
36
38
 
39
+ <a name="version" />
40
+ ## Compatibility
41
+
42
+ The following versions of grape, grape-entity and grape-swagger can currently be used together.
43
+
44
+ grape-swagger | grape | grape-entity
45
+ --------------|-------------------------|-------------
46
+ 0.10.5 | >= 0.10.0 ... <= 0.14.0 | < 0.5.0
47
+ 0.11.0 | >= 0.16.2 | < 0.5.0
48
+ 0.20.1 | >= 0.12.0 ... <= 0.14.0 | <= 0.5.1
49
+
50
+
37
51
  <a name="swagger-spec" />
38
52
  ## Swagger-Spec
39
53
 
@@ -9,6 +9,7 @@ require 'grape-swagger/doc_methods/path_string'
9
9
  require 'grape-swagger/doc_methods/tag_name_description'
10
10
  require 'grape-swagger/doc_methods/parse_params'
11
11
  require 'grape-swagger/doc_methods/move_params'
12
+ require 'grape-swagger/doc_methods/headers'
12
13
 
13
14
  module GrapeSwagger
14
15
  module DocMethods
@@ -0,0 +1,18 @@
1
+ module GrapeSwagger
2
+ module DocMethods
3
+ class Headers
4
+ class << self
5
+ def parse(route)
6
+ route.route_headers.to_a.map do |route_header|
7
+ route_header.tap do |header|
8
+ hash = header[1]
9
+ description = hash.delete('description')
10
+ hash[:documentation] = { desc: description, in: 'header' }
11
+ hash[:type] = hash['type'].titleize if hash['type']
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -43,11 +43,7 @@ module GrapeSwagger
43
43
  end
44
44
 
45
45
  def document_default_value(settings)
46
- default_value = settings[:default] || nil
47
- example = settings[:example] || nil
48
-
49
- @parsed_param[:default] = example if example
50
- @parsed_param[:default] = default_value if default_value && example.blank?
46
+ @parsed_param[:default] = settings[:default] if settings[:default].present?
51
47
  end
52
48
 
53
49
  def document_type_and_format(data_type)
@@ -24,7 +24,7 @@ module Grape
24
24
  swagger: '2.0',
25
25
  produces: content_types_for(target_class),
26
26
  authorizations: options[:authorizations],
27
- host: GrapeSwagger::DocMethods::OptionalObject.build(:host, options, request.env['HTTP_HOST']),
27
+ host: GrapeSwagger::DocMethods::OptionalObject.build(:host, options, request.host_with_port),
28
28
  basePath: GrapeSwagger::DocMethods::OptionalObject.build(:base_path, options, request.env['SCRIPT_NAME']),
29
29
  tags: GrapeSwagger::DocMethods::TagNameDescription.build(options),
30
30
  schemes: options[:schemes].is_a?(String) ? [options[:schemes]] : options[:schemes]
@@ -105,7 +105,6 @@ module Grape
105
105
  def method_object(route, options, path)
106
106
  method = {}
107
107
  method[:description] = description_object(route, options[:markdown])
108
- method[:headers] = route.route_headers if route.route_headers
109
108
  method[:produces] = produces_object(route, options[:produces] || options[:format])
110
109
  method[:consumes] = consumes_object(route, options[:format])
111
110
  method[:parameters] = params_object(route)
@@ -194,14 +193,13 @@ module Grape
194
193
  def partition_params(route)
195
194
  declared_params = route.route_settings[:declared_params] if route.route_settings[:declared_params].present?
196
195
  required, exposed = route.route_params.partition { |x| x.first.is_a? String }
197
-
196
+ required.concat GrapeSwagger::DocMethods::Headers.parse(route) unless route.route_headers.nil?
198
197
  default_type(required)
199
198
  default_type(exposed)
200
199
 
201
- unless declared_params.nil?
200
+ unless declared_params.nil? && route.route_headers.nil?
202
201
  request_params = parse_request_params(required)
203
202
  end
204
-
205
203
  if !exposed.empty?
206
204
  exposed_params = exposed.each_with_object({}) { |x, memo| memo[x.first] = x.last }
207
205
  properties = parse_response_params(exposed_params)
@@ -215,8 +213,7 @@ module Grape
215
213
  @definitions[key] = { type: 'object', properties: properties } unless @definitions.key?(key)
216
214
  @definitions[key][:properties].merge!(properties) if @definitions.key?(key)
217
215
  end
218
-
219
- return route.route_params if route.route_params && !route.route_settings[:declared_params].present?
216
+ return route.route_params if route.route_params.present? && !route.route_settings[:declared_params].present?
220
217
  request_params || {}
221
218
  end
222
219
 
@@ -244,6 +241,7 @@ module Grape
244
241
  return if params.nil?
245
242
 
246
243
  params.each_with_object({}) do |x, memo|
244
+ next if x[1].fetch(:documentation, {}).fetch(:in, nil).to_s == 'header'
247
245
  x[0] = x.last[:as] if x.last[:as]
248
246
 
249
247
  model = x.last[:using] if x.last[:using].present?
@@ -1,3 +1,3 @@
1
1
  module GrapeSwagger
2
- VERSION = '0.20.1'.freeze
2
+ VERSION = '0.20.2'.freeze
3
3
  end
@@ -36,9 +36,13 @@ describe 'headers' do
36
36
  end
37
37
 
38
38
  specify do
39
- expect(subject['paths']['/use_headers']['get']).to include('headers')
40
- expect(subject['paths']['/use_headers']['get']['headers']).to eql({
41
- "X-Rate-Limit-Limit"=>{"description"=>"The number of allowed requests in the current period", "type"=>"integer"}
42
- })
39
+ expect(subject['paths']['/use_headers']['get']['parameters']).to eql([
40
+ {"in"=>"header",
41
+ "name"=>"X-Rate-Limit-Limit",
42
+ "description"=>"The number of allowed requests in the current period",
43
+ "type"=>"integer",
44
+ "format" => "int32",
45
+ "required"=>false},
46
+ ])
43
47
  end
44
48
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'host in the swagger_doc' do
4
+ include_context "the api entities"
5
+
6
+ before :all do
7
+ module TheApi
8
+ class EmptyApi < Grape::API
9
+ format :json
10
+
11
+ add_swagger_documentation
12
+ end
13
+ end
14
+ end
15
+
16
+ def app
17
+ TheApi::EmptyApi
18
+ end
19
+
20
+ describe 'host should include port' do
21
+ subject do
22
+ get 'http://example.com:8080/swagger_doc'
23
+ JSON.parse(last_response.body)
24
+ end
25
+
26
+ specify do
27
+ expect(subject['host']).to eq 'example.com:8080'
28
+ end
29
+ end
30
+
31
+ describe 'respect X-Forwarded-Host over Host header' do
32
+ subject do
33
+ header 'Host', 'dummy.example.com'
34
+ header 'X-Forwarded-Host', 'real.example.com'
35
+ get '/swagger_doc'
36
+ JSON.parse(last_response.body)
37
+ end
38
+
39
+ specify do
40
+ expect(subject['host']).to eq 'real.example.com'
41
+ end
42
+ end
43
+ end
@@ -50,7 +50,7 @@ describe 'Params Types' do
50
50
 
51
51
  it 'has consistent types' do
52
52
  types = subject.map { |param| param['type'] }
53
- expect(types).to eq(%w(string))
53
+ expect(types).to eq(%w(string string))
54
54
  end
55
55
  end
56
56
  end
@@ -97,10 +97,10 @@ describe 'a simple mounted api' do
97
97
  "/simple_with_headers"=>{
98
98
  "get"=>{
99
99
  "description"=>"this gets something else",
100
- "headers"=>{
101
- "XAuthToken"=>{"description"=>"A required header.", "required"=>true},
102
- "XOtherHeader"=>{"description"=>"An optional header.", "required"=>false}},
103
100
  "produces"=>["application/json"],
101
+ "parameters"=>[
102
+ {"in"=>"header", "name"=>"XAuthToken", "description"=>"A required header.", "type"=>"string", "required"=>true},
103
+ {"in"=>"header", "name"=>"XOtherHeader", "description"=>"An optional header.", "type"=>"string", "required"=>false}],
104
104
  "tags"=>["simple_with_headers"],
105
105
  "operationId"=>"getSimpleWithHeaders",
106
106
  "responses"=>{
@@ -203,10 +203,10 @@ describe 'a simple mounted api' do
203
203
  "/simple_with_headers"=>{
204
204
  "get"=>{
205
205
  "description"=>"this gets something else",
206
- "headers"=>{
207
- "XAuthToken"=>{"description"=>"A required header.", "required"=>true},
208
- "XOtherHeader"=>{"description"=>"An optional header.", "required"=>false}},
209
206
  "produces"=>["application/json"],
207
+ "parameters"=>[
208
+ {"in"=>"header", "name"=>"XAuthToken", "description"=>"A required header.", "type"=>"string", "required"=>true},
209
+ {"in"=>"header", "name"=>"XOtherHeader", "description"=>"An optional header.", "type"=>"string", "required"=>false}],
210
210
  "tags"=>["simple_with_headers"],
211
211
  "operationId"=>"getSimpleWithHeaders",
212
212
  "responses"=>{
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.1
4
+ version: 0.20.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Vandecasteele
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-17 00:00:00.000000000 Z
11
+ date: 2016-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grape
@@ -273,6 +273,7 @@ files:
273
273
  - lib/grape-swagger/doc_methods.rb
274
274
  - lib/grape-swagger/doc_methods/data_type.rb
275
275
  - lib/grape-swagger/doc_methods/extensions.rb
276
+ - lib/grape-swagger/doc_methods/headers.rb
276
277
  - lib/grape-swagger/doc_methods/move_params.rb
277
278
  - lib/grape-swagger/doc_methods/operation_id.rb
278
279
  - lib/grape-swagger/doc_methods/optional_object.rb
@@ -325,6 +326,7 @@ files:
325
326
  - spec/swagger_v2/form_params_spec.rb
326
327
  - spec/swagger_v2/grape-swagger_spec.rb
327
328
  - spec/swagger_v2/hide_api_spec.rb
329
+ - spec/swagger_v2/host.rb
328
330
  - spec/swagger_v2/mounted_target_class_spec.rb
329
331
  - spec/swagger_v2/namespace_tags_prefix_spec.rb
330
332
  - spec/swagger_v2/namespace_tags_spec.rb
@@ -403,6 +405,7 @@ test_files:
403
405
  - spec/swagger_v2/form_params_spec.rb
404
406
  - spec/swagger_v2/grape-swagger_spec.rb
405
407
  - spec/swagger_v2/hide_api_spec.rb
408
+ - spec/swagger_v2/host.rb
406
409
  - spec/swagger_v2/mounted_target_class_spec.rb
407
410
  - spec/swagger_v2/namespace_tags_prefix_spec.rb
408
411
  - spec/swagger_v2/namespace_tags_spec.rb