rspec_api_documentation 4.4.0 → 4.5.0

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: b1f384a163dd016f784e49be257ea8c41b36c462
4
- data.tar.gz: dd948cacf84ba686f5368bafdc39bf70dfa5fc2b
3
+ metadata.gz: 8626bf0bd0d6df280166c00c348fa3223d989f74
4
+ data.tar.gz: d95564e9c4135d446e3652cc4186290aaef69473
5
5
  SHA512:
6
- metadata.gz: 0eeb83e3a3f341a0df20d1cd50826d34ba29dc45dde5ddfcc1b82d8be3c36936cbcaf093d7f6d2c96b5fb44af6f5954e8267069b172b6030904e418377245837
7
- data.tar.gz: 84093be0b80f3550526e337e0038dfab66e857cd66e3629e29ca3568e1a87e486a54b29897f0ed7b37ef58f744e7b2eb53d4d5c99db5b8e5cd4d03f63fc0ad80
6
+ metadata.gz: ccb8359e19e031785d56aaa2022c75c1dc83678e4f0307b5c877bd3eb51767daf513e58ad02ea3422ab2929fe32f2ee1d1c348e49b80f476cd215f3935377ec3
7
+ data.tar.gz: 5ca2508704c946625a495a8875e56180cd337e9f4fa6bc5b28a67d46f9e776f55da68b5a6d1d7dfcfdcf243a77ad743f170e14d935e525944dafd3c2113f71f0
@@ -9,7 +9,7 @@ require 'json'
9
9
  module RspecApiDocumentation
10
10
  extend ActiveSupport::Autoload
11
11
 
12
- require 'rspec_api_documentation/railtie' if defined?(Rails)
12
+ require 'rspec_api_documentation/railtie' if defined?(Rails::Railtie)
13
13
  include ActiveSupport::JSON
14
14
 
15
15
  eager_autoload do
@@ -68,7 +68,7 @@ module RspecApiDocumentation
68
68
  request_metadata[:request_content_type] = request_content_type
69
69
  request_metadata[:response_status] = status
70
70
  request_metadata[:response_status_text] = Rack::Utils::HTTP_STATUS_CODES[status]
71
- request_metadata[:response_body] = response_body.empty? ? nil : response_body
71
+ request_metadata[:response_body] = record_response_body(response_content_type, response_body)
72
72
  request_metadata[:response_headers] = response_headers
73
73
  request_metadata[:response_content_type] = response_content_type
74
74
  request_metadata[:curl] = Curl.new(method, path, request_body, request_headers)
@@ -85,6 +85,17 @@ module RspecApiDocumentation
85
85
  request_headers || {}
86
86
  end
87
87
 
88
+ def record_response_body(response_content_type, response_body)
89
+ return nil if response_body.empty?
90
+ if response_body.encoding == Encoding::ASCII_8BIT
91
+ "[binary data]"
92
+ elsif response_content_type =~ /application\/json/
93
+ JSON.pretty_generate(JSON.parse(response_body))
94
+ else
95
+ response_body
96
+ end
97
+ end
98
+
88
99
  def clean_out_uploaded_data(params, request_body)
89
100
  params.each do |_, value|
90
101
  if value.is_a?(Hash)
@@ -148,16 +148,24 @@ module RspecApiDocumentation::DSL
148
148
 
149
149
  def set_param(hash, param)
150
150
  key = param[:name]
151
- return hash if !respond_to?(key) || in_path?(key)
152
151
 
153
- if param[:scope]
154
- hash[param[:scope].to_s] ||= {}
155
- hash[param[:scope].to_s][key] = send(key)
156
- else
157
- hash[key] = send(key)
152
+ keys = [param[:scope], key].flatten.compact
153
+ method_name = keys.join('_')
154
+
155
+ return hash if in_path?(method_name)
156
+
157
+ unless respond_to?(method_name)
158
+ method_name = key
159
+ return hash unless respond_to?(method_name)
158
160
  end
159
161
 
160
- hash
162
+ hash.deep_merge(build_param_hash(keys, method_name))
161
163
  end
164
+
165
+ def build_param_hash(keys, method_name)
166
+ value = keys[1] ? build_param_hash(keys[1..-1], method_name) : send(method_name)
167
+ { keys[0].to_s => value }
168
+ end
169
+
162
170
  end
163
171
  end
@@ -6,7 +6,7 @@ module RspecApiDocumentation::DSL
6
6
  module ClassMethods
7
7
  def self.define_action(method)
8
8
  define_method method do |*args, &block|
9
- options = if args.last.is_a?(Hash) then args.pop else {} end
9
+ options = args.extract_options!
10
10
  options[:method] = method
11
11
  options[:route] = args.first
12
12
  options[:api_doc_dsl] = :endpoint
@@ -38,7 +38,10 @@ module RspecApiDocumentation::DSL
38
38
  context(*args, &block)
39
39
  end
40
40
 
41
- def parameter(name, description, options = {})
41
+ def parameter(name, *args)
42
+ options = args.extract_options!
43
+ description = args.pop || "#{Array(options[:scope]).join(" ")} #{name}".humanize
44
+
42
45
  parameters.push(options.merge(:name => name.to_s, :description => description))
43
46
  end
44
47
 
@@ -89,7 +92,7 @@ module RspecApiDocumentation::DSL
89
92
  requests = example.metadata[:requests]
90
93
  example.metadata[:requests] = []
91
94
 
92
- instance_eval &block
95
+ instance_eval(&block)
93
96
 
94
97
  example.metadata[:requests] = requests
95
98
  end
@@ -28,6 +28,21 @@ module RspecApiDocumentation
28
28
  "#{basename}.#{extension}"
29
29
  end
30
30
 
31
+ def parameters
32
+ super.each do |parameter|
33
+ if parameter.has_key?(:scope)
34
+ scope = Array(parameter[:scope]).each_with_index.map do |scope, index|
35
+ if index == 0
36
+ scope
37
+ else
38
+ "[#{scope}]"
39
+ end
40
+ end.join
41
+ parameter[:scope] = scope
42
+ end
43
+ end
44
+ end
45
+
31
46
  def requests
32
47
  super.map do |hash|
33
48
  hash[:request_headers_text] = format_hash(hash[:request_headers])
@@ -51,7 +51,9 @@ module RspecApiDocumentation
51
51
  {
52
52
  :description => example.description,
53
53
  :link => "#{example.dirname}/#{example.filename}",
54
- :groups => example.metadata[:document]
54
+ :groups => example.metadata[:document],
55
+ :route => example.route,
56
+ :method => example.metadata[:method]
55
57
  }
56
58
  }
57
59
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_api_documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.4.0
4
+ version: 4.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Cahoon
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-04-28 00:00:00.000000000 Z
13
+ date: 2015-10-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec