rspec_api_documentation 4.3.0 → 4.4.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: cb2fb26b05b35089944ce6878bb2d866b2c64831
4
- data.tar.gz: af9e4d78d7b53feb8233e9bf0770b1b0d168fbd7
3
+ metadata.gz: b1f384a163dd016f784e49be257ea8c41b36c462
4
+ data.tar.gz: dd948cacf84ba686f5368bafdc39bf70dfa5fc2b
5
5
  SHA512:
6
- metadata.gz: 9677cb19ce2dc7e77067feaa666cda455ea57bf018b16119f2b94a1d188fb1e8d433e1cba207a400f43e7050a0161d19b391744940257e0734a31b6749eb92f5
7
- data.tar.gz: 381d5c452e78ebd9ea62f8435d41211cb1c28ab48de53f0b8bd392a44ef89fd297bdf9b789e1305caf5e6ac5f50904ea023b08bc9a99e5804367705ef7a1b992
6
+ metadata.gz: 0eeb83e3a3f341a0df20d1cd50826d34ba29dc45dde5ddfcc1b82d8be3c36936cbcaf093d7f6d2c96b5fb44af6f5954e8267069b172b6030904e418377245837
7
+ data.tar.gz: 84093be0b80f3550526e337e0038dfab66e857cd66e3629e29ca3568e1a87e486a54b29897f0ed7b37ef58f744e7b2eb53d4d5c99db5b8e5cd4d03f63fc0ad80
@@ -1,6 +1,7 @@
1
1
  require 'active_support'
2
2
  require 'active_support/inflector'
3
3
  require 'active_support/core_ext/hash/conversions'
4
+ require 'active_support/core_ext/hash/deep_merge'
4
5
  require 'cgi'
5
6
  require 'json'
6
7
 
@@ -45,11 +45,6 @@ a{
45
45
  font-weight: inherit;
46
46
  }
47
47
 
48
- p {
49
- padding: 15px;
50
- font-size: 130%;
51
- }
52
-
53
48
  h1, h2, h3, h4, h5, h6 {
54
49
  font-weight: bold;
55
50
  color: #404040;
@@ -99,4 +94,4 @@ table th, table td {
99
94
  padding: 10px 10px 9px;
100
95
  line-height: 18px;
101
96
  text-align: left;
102
- }
97
+ }
@@ -84,5 +84,19 @@ module RspecApiDocumentation
84
84
  def headers(method, path, params, request_headers)
85
85
  request_headers || {}
86
86
  end
87
+
88
+ def clean_out_uploaded_data(params, request_body)
89
+ params.each do |_, value|
90
+ if value.is_a?(Hash)
91
+ if value.has_key?(:tempfile)
92
+ data = value[:tempfile].read
93
+ request_body = request_body.gsub(data, "[uploaded data]")
94
+ else
95
+ request_body = clean_out_uploaded_data(value,request_body)
96
+ end
97
+ end
98
+ end
99
+ request_body
100
+ end
87
101
  end
88
102
  end
@@ -106,6 +106,18 @@ module RspecApiDocumentation
106
106
  @client_method ||= :client
107
107
  end
108
108
 
109
+ def disable_dsl_status!
110
+ RspecApiDocumentation::DSL::Endpoint.module_eval <<-RUBY
111
+ undef status
112
+ RUBY
113
+ end
114
+
115
+ def disable_dsl_method!
116
+ RspecApiDocumentation::DSL::Endpoint.module_eval <<-RUBY
117
+ undef method
118
+ RUBY
119
+ end
120
+
109
121
  def settings
110
122
  @settings ||= {}
111
123
  end
@@ -35,3 +35,8 @@ RSpec.configuration.include RspecApiDocumentation::DSL::Resource, :api_doc_dsl =
35
35
  RSpec.configuration.include RspecApiDocumentation::DSL::Endpoint, :api_doc_dsl => :endpoint
36
36
  RSpec.configuration.include RspecApiDocumentation::DSL::Callback, :api_doc_dsl => :callback
37
37
  RSpec.configuration.backtrace_exclusion_patterns << %r{lib/rspec_api_documentation/dsl/}
38
+
39
+ if defined? RSpec::Rails
40
+ RSpec::Rails::DIRECTORY_MAPPINGS[:acceptance] = %w[spec acceptance]
41
+ RSpec.configuration.infer_spec_type_from_file_location!
42
+ end
@@ -8,7 +8,7 @@ module RspecApiDocumentation::DSL
8
8
  extend ActiveSupport::Concern
9
9
  include Rack::Test::Utils
10
10
 
11
- delegate :response_headers, :status, :response_status, :response_body, :to => :rspec_api_documentation_client
11
+ delegate :response_headers, :response_status, :response_body, :to => :rspec_api_documentation_client
12
12
 
13
13
  module ClassMethods
14
14
  def example_request(description, params = {}, &block)
@@ -35,16 +35,16 @@ module RspecApiDocumentation::DSL
35
35
  params_or_body = nil
36
36
  path_or_query = path
37
37
 
38
- if method == :get && !query_string.blank?
38
+ if http_method == :get && !query_string.blank?
39
39
  path_or_query += "?#{query_string}"
40
40
  else
41
- if respond_to?(:raw_post)
41
+ if respond_to?(:raw_post)
42
42
  params_or_body = raw_post
43
43
  else
44
44
  formatter = RspecApiDocumentation.configuration.post_body_formatter
45
45
  case formatter
46
46
  when :json
47
- params_or_body = params.to_json
47
+ params_or_body = params.empty? ? nil : params.to_json
48
48
  when :xml
49
49
  params_or_body = params.to_xml
50
50
  when Proc
@@ -55,7 +55,7 @@ module RspecApiDocumentation::DSL
55
55
  end
56
56
  end
57
57
 
58
- rspec_api_documentation_client.send(method, path_or_query, params_or_body, headers)
58
+ rspec_api_documentation_client.send(http_method, path_or_query, params_or_body, headers)
59
59
  end
60
60
 
61
61
  def query_string
@@ -66,7 +66,7 @@ module RspecApiDocumentation::DSL
66
66
  parameters = example.metadata.fetch(:parameters, {}).inject({}) do |hash, param|
67
67
  set_param(hash, param)
68
68
  end
69
- parameters.merge!(extra_params)
69
+ parameters.deep_merge!(extra_params)
70
70
  parameters
71
71
  end
72
72
 
@@ -87,10 +87,18 @@ module RspecApiDocumentation::DSL
87
87
  end
88
88
  end
89
89
 
90
- def method
90
+ def http_method
91
91
  example.metadata[:method]
92
92
  end
93
93
 
94
+ def method
95
+ http_method
96
+ end
97
+
98
+ def status
99
+ rspec_api_documentation_client.status
100
+ end
101
+
94
102
  def in_path?(param)
95
103
  path_params.include?(param)
96
104
  end
@@ -128,6 +136,7 @@ module RspecApiDocumentation::DSL
128
136
  def extra_params
129
137
  return {} if @extra_params.nil?
130
138
  @extra_params.inject({}) do |h, (k, v)|
139
+ v = v.is_a?(Hash) ? v.stringify_keys : v
131
140
  h[k.to_s] = v
132
141
  h
133
142
  end
@@ -51,28 +51,25 @@ module RspecApiDocumentation::DSL
51
51
  end
52
52
 
53
53
  private
54
- def parameters
55
- metadata[:parameters] ||= []
56
- if superclass_metadata && metadata[:parameters].equal?(superclass_metadata[:parameters])
57
- metadata[:parameters] = Marshal.load(Marshal.dump(superclass_metadata[:parameters]))
54
+
55
+ def safe_metadata(field, default)
56
+ metadata[field] ||= default
57
+ if superclass_metadata && metadata[field].equal?(superclass_metadata[field])
58
+ metadata[field] = Marshal.load(Marshal.dump(superclass_metadata[field]))
58
59
  end
59
- metadata[:parameters]
60
+ metadata[field]
61
+ end
62
+
63
+ def parameters
64
+ safe_metadata(:parameters, [])
60
65
  end
61
66
 
62
67
  def response_fields
63
- metadata[:response_fields] ||= []
64
- if superclass_metadata && metadata[:response_fields].equal?(superclass_metadata[:response_fields])
65
- metadata[:response_fields] = Marshal.load(Marshal.dump(superclass_metadata[:response_fields]))
66
- end
67
- metadata[:response_fields]
68
+ safe_metadata(:response_fields, [])
68
69
  end
69
70
 
70
71
  def headers
71
- metadata[:headers] ||= {}
72
- if superclass_metadata && metadata[:headers].equal?(superclass_metadata[:headers])
73
- metadata[:headers] = Marshal.load(Marshal.dump(superclass_metadata[:headers]))
74
- end
75
- metadata[:headers]
72
+ safe_metadata(:headers, {})
76
73
  end
77
74
 
78
75
  def parameter_keys
@@ -8,6 +8,7 @@ module RspecApiDocumentation
8
8
  # HTTP_ACCEPT_CHARSET => Accept-Charset
9
9
  if key =~ /^(HTTP_|CONTENT_TYPE)/
10
10
  header = key.gsub(/^HTTP_/, '').titleize.split.join("-")
11
+ header.concat('-Id') if key.scan(/_ID\Z/).any?
11
12
  headers[header] = value
12
13
  end
13
14
  end
@@ -94,21 +94,6 @@ module RspecApiDocumentation
94
94
 
95
95
  private
96
96
 
97
- def clean_out_uploaded_data(params, request_body)
98
- params.each do |_, value|
99
- if value.is_a?(Hash)
100
- if value.has_key?(:tempfile)
101
- data = value[:tempfile].read
102
- request_body = request_body.gsub(data, "[uploaded data]")
103
- else
104
- request_body = clean_out_uploaded_data(value,request_body)
105
- end
106
- end
107
- end
108
- request_body
109
- end
110
-
111
-
112
97
  def http_test_session
113
98
  ::Faraday.new(:url => options[:host]) do |faraday|
114
99
  faraday.request :url_encoded # form-encode POST params
@@ -53,20 +53,6 @@ module RspecApiDocumentation
53
53
 
54
54
  private
55
55
 
56
- def clean_out_uploaded_data(params,request_body)
57
- params.each do |_, value|
58
- if value.is_a?(Hash)
59
- if value.has_key?(:tempfile)
60
- data = value[:tempfile].read
61
- request_body = request_body.gsub(data, "[uploaded data]")
62
- else
63
- request_body = clean_out_uploaded_data(value,request_body)
64
- end
65
- end
66
- end
67
- request_body
68
- end
69
-
70
56
  def rack_test_session
71
57
  @rack_test_session ||= Struct.new(:app) do
72
58
  begin
@@ -19,7 +19,7 @@ module RspecApiDocumentation
19
19
  end
20
20
 
21
21
  def dirname
22
- resource_name.downcase.gsub(/\s+/, '_').gsub(":", "_")
22
+ resource_name.to_s.downcase.gsub(/\s+/, '_').gsub(":", "_")
23
23
  end
24
24
 
25
25
  def filename
@@ -44,7 +44,7 @@ module RspecApiDocumentation
44
44
  end
45
45
 
46
46
  def resource_name
47
- example.resource_name.downcase.gsub(/\s+/, '_')
47
+ example.resource_name.to_s.downcase.gsub(/\s+/, '_')
48
48
  end
49
49
 
50
50
  def description
@@ -74,7 +74,7 @@ module RspecApiDocumentation
74
74
  end
75
75
 
76
76
  def dirname
77
- resource_name.downcase.gsub(/\s+/, '_')
77
+ resource_name.to_s.downcase.gsub(/\s+/, '_').sub(/^\//,'')
78
78
  end
79
79
 
80
80
  def filename
@@ -16,7 +16,7 @@
16
16
  <h3>{{ http_method }} {{ route }}</h3>
17
17
  {{# explanation }}
18
18
  <p class="explanation">
19
- {{ explanation }}
19
+ {{{ explanation }}}
20
20
  </p>
21
21
  {{/ explanation }}
22
22
 
@@ -81,8 +81,10 @@
81
81
  {{# requests }}
82
82
  <h3>Request</h3>
83
83
 
84
- <h4>Headers</h4>
85
- <pre class="request headers">{{ request_headers_text }}</pre>
84
+ {{# request_headers_text }}
85
+ <h4>Headers</h4>
86
+ <pre class="request headers">{{ request_headers_text }}</pre>
87
+ {{/ request_headers_text }}
86
88
 
87
89
  <h4>Route</h4>
88
90
  <pre class="request route highlight">{{ request_method }} {{ request_path }}</pre>
@@ -104,8 +106,10 @@
104
106
 
105
107
  {{# response_status }}
106
108
  <h3>Response</h3>
107
- <h4>Headers</h4>
108
- <pre class="response headers">{{ response_headers_text }}</pre>
109
+ {{# response_headers_text }}
110
+ <h4>Headers</h4>
111
+ <pre class="response headers">{{ response_headers_text }}</pre>
112
+ {{/ response_headers_text }}
109
113
  <h4>Status</h4>
110
114
  <pre class="response status">{{ response_status }} {{ response_status_text}}</pre>
111
115
  {{# response_body }}
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.3.0
4
+ version: 4.4.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: 2014-10-09 00:00:00.000000000 Z
13
+ date: 2015-04-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.4.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: fakefs
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -309,7 +323,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
309
323
  version: 1.3.6
310
324
  requirements: []
311
325
  rubyforge_project:
312
- rubygems_version: 2.2.2
326
+ rubygems_version: 2.4.5
313
327
  signing_key:
314
328
  specification_version: 4
315
329
  summary: A double black belt for your docs